Add CSS inset box-shadow to parent element over the top of a child image - shadow

I'm trying to add shadow to the parent object where an child <img> element is positioned inside it. I wan the inset shadow to overlap the image.
My HTML code is:
<section class="highlights">
<img src="images/hero.jpg" alt="" />
</section><!-- End section.highlights -->
and CSS:
.highlights {
height: 360px;
padding: 0;
position: relative;
overflow: hidden;
opacity: 0.9;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
z-index:1;
}
.highlights img {
height: auto;
width: 100%;
margin: 0 auto;
display: block;
position: relative;
}
.highlights {
-webkit-box-shadow: inset 0 0 10px 0 rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 10px 0 rgba(0, 0, 0, 0.2);
}
The shadow is not appearing for me. What did I do wrong?

The problem is that the image is rendered over the top of the inset box-shadow.
There are 2 possible ways I can think of doing this, one using opacity on the <img> to push it behind the shadow and the second way to position the inset shadow over the top of the image. I prefer the second approach because the full opacity of the image can be retained.
Note: I have made the border large and red for demonstration.
Solution 1 demo
HTML
<section class="highlights">
<img src="http://lorempixel.com/500/360/city/1/" alt=""/>
</section>
CSS
.highlights {
height: 360px;
padding: 0;
position: relative;
overflow: hidden;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.highlights img {
height: auto;
width: 100%;
margin: 0 auto;
display: block;
opacity: .9;
}
.highlights {
-webkit-box-shadow: inset 0 0 10px 0 rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 25px 25px red;
}
Solution 2 demo
CSS
.highlights {
height: 360px;
padding: 0;
position: relative;
overflow: hidden;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.highlights img {
height: auto;
width: 100%;
margin: 0 auto;
display: block;
}
.highlights::before {
-webkit-box-shadow: inset 0 0 10px 0 rgba(0, 0, 0, 0.2);
box-shadow: inset 0 0 25px 25px red;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
content: "";
}

Related

html css background image of div box

I am trying to make a div box with an background image for my website.
The div box itself works perfectly but there is no background image in it.
Anyone have an idea?
.box {
width: 600px;
height: 400px;
padding: 20px;
box-shadow: 0px 0px 10px 2px grey;
margin: 100px auto;
border: 10px solid red;
background-image: url(/img/header.jpg);
background-size: cover;
}
Try pointing to the absolute path:
.box {
width: 600px;
height: 400px;
padding: 20px;
box-shadow: 0px 0px 10px 2px grey;
margin: 100px auto;
border: 10px solid red;
background-image: url("http://www.website.com/img/header.jpg");
background-size: cover;
}
JSFIDDLE

How do I blur the border of my image div?

Can somebody help me in this?
I have tried box shadow and border but couldn't get the transparency in the border:
<div class="" style="border-radius: 125px;
width: 125px;
height: 125px;
margin: auto;
box-shadow: 0 0 0 6px rgba(68,68,68,0.25), 0 0 0 15px rgba(68,68,68,0.35); ">
<img src="images/tracks_bg.png" width="100%" height="100%" style="border-radius: 50%; opacity: 1 !important;">
</div>
You could
Use a wrapper DIV
Inside your wrapper place an absolutely positioned (full-size) blurred DIV
Inside your wrapper place a circle with the same background image as the blurred DIV
Play with box-shadow n the circle track image DIV element
/*QuickReset*/ *{margin:0;box-sizing:border-box;} html,body{height:100%;font:14px/1.4 sans-serif;}
.player {
position: relative;
overflow: hidden;
height: 100vh;
background: #000;
}
.trackImageBlur {
position: absolute;
background: none 50% 50% / cover;
opacity:0.6; /* lower opacity so we can transpare the parent's #000 bg */
padding: 4vw; margin: -4vw; /* prevent seeing blurred-out edges */
box-sizing: content-box; /* apply normal paddings (on the outside) */
width: 100%;
height: 100%;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
.trackImage {
position: absolute;
background: none 50% 50% / 150%;
width: 60vh;
height: 60vh;
border-radius: 50%;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
box-shadow:
0 0 0 20vh rgba(0, 0, 0, 0.2),
0 0 0 12vh rgba(0, 0, 0, 0.2),
0 0 0 9vh rgba(0, 0, 0, 0.3),
0 0 0 3vh rgba(0, 0, 0, 0.4);
}
<div class="player">
<div class="trackImageBlur" style="background-image:url('//i.stack.imgur.com/ItuWP.png')"></div>
<div class="trackImage" style="background-image:url('//i.stack.imgur.com/ItuWP.png')"></div>
</div>
Try this, I'm currently using this box-shadow css code and it works fine for me
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);

Centering div with border on the page

I need to center div on my page. Dimensions are not fixed. Here is what I do to center it
background-image: url(../img/icon.png);
background-repeat:no-repeat;
background-size:cover;
border: 5px solid;
border-radius: 10px;
border-color: #ffffff;
box-shadow: 0 10px 6px -3px black;;
position: absolute;
height: 85%;
width: 82%;
top: 7.5%;
left: 9%;
And this works fine if I don't have a border property set. If I set it to lets say 5px div is not horizontally centered anymore. How can I fix this?
Add box-sizing: border-box;. So the border does not extend your div.
More box-sizing: css-tricks.com/box-sizing
try
margin-left:auto;
margin-right:auto;
also, box-shadow: 0 10px 6px -3px black;; should not have the 2nd semicolon.
Try this:
.yourclass{
background:url(../img/icon.png) no-repeat;
background-size:cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-ms-background-size: cover;
-0-background-size: cover;
border: 5px solid;
border-radius: 10px;
border-color: #ffffff;
box-shadow: 0 10px 6px -3px black;;
display: table;
margin: 0 auto;
height: 85%;
width: 82%;
vertical-align: middle;
Just saying: When you use background method, you don't need to type like: "background-image" with "background-repeat: no-repeat", you can just type like "background:url(...) no-repeat" - making it smaller and more organized.

Black line between cover-img and cover-body

I used a cover image to fill the sidebar, but there's a black line appearing between the cover image that is not filled with the body and cover body itself. You can see it in action here. I'm pretty sure it's not the border or anything.
Thanks!
HTML
<aside id="sidebar">
<div class="cover-img">
<div class="cover-body">
<div class="logo" style="margin-bottom:30px;">
CSS
.cover-img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
-webkit-box-shadow: 1px 0 1px rgba(0,0,0,0.15);
-moz-box-shadow: 1px 0 1px rgba(0,0,0,0.15);
box-shadow: 1px 0 1px rgba(0,0,0,0.15);
}
.cover-body {
position: absolute;
bottom: 0;
padding: 50px 10% 10%;
width: 100%;
height: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.cover-body:before {
content: '';
position: absolute;
top: -80px;
right: 0;
bottom: 0;
left: 0;
background-repeat: repeat-x;
background-image: -webkit-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 25%,rgba(0,0,0,0) 100%);
background-image: -moz-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 25%,rgba(0,0,0,0) 100%);
background-image: -ms-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 25%,rgba(0,0,0,0) 100%);
background-image: -o-linear-gradient(bottom,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 25%,rgba(0,0,0,0) 100%);
background-image: linear-gradient(to top,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.3) 25%,rgba(0,0,0,0) 100%);
}
.cover-body {
padding-top: 20px !important;
padding-bottom: 0 !important;
}
You have a box-shadow on .about-blog-author that's what's doing it:
-webkit-box-shadow: 0 -1px 0 rgba(0,0,0,0.3);
-moz-box-shadow: 0 -1px 0 rgba(0,0,0,0.3);
box-shadow: 0 -1px 0 rgba(0,0,0,0.3);
Remove it or change -1px to 0
Its your box-shadow that you specify in the .cover-image class. You can remove it or adjust your code and designs accordingly so that you don't see it there.
Try removing the box-shadow property, and you'll see that that line disappears.

Using the Z-index in CSS

I have 3 divs. I am trying to place the #cover div behind the #cover-overlay div which should be behind the #user-stuff div. I can't seem to get my z-index to work quite right. What am I doing wrong?
JSFIDDLE: http://jsfiddle.net/BafSL/1/
My CSS:
#cover {
position: relative;
height: 350px;
width: 920px;
/* background: url('http://images.nationalgeographic.com/wpf/media-
live/photos/000/621/cache/praia-dos-tres-irmaos-beach-portugal_62194_990x742.jpg') no-
repeat center center; */
background: url('https://sphotos-b.xx.fbcdn.net/hphotos-
ash4/486464_10150990114607410_529660447_n.jpg') no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
z-index: 0;
}
#cover-overlay {
position: absolute;
top: 0px;
-webkit-background-clip: border-box;
-webkit-background-origin: padding-box;
-webkit-background-size: auto;
background-attachment: scroll;
background-clip: border-box;
background-color: rgba(0, 0, 0, 0);
background-image: -webkit-linear-gradient(bottom, rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0,
0.54902) 100%);
background-origin: padding-box;
background-size: auto;
bottom: 50px;
color: rgb(51, 51, 51);
display: block;
font-family: Arial, sans-serif;
font-size: 14px;
height: 200px;
line-height: 16px;
position: absolute;
text-align: center;
text-shadow: rgb(255, 255, 255) 0px 1px 0px;
width: 100%;
z-index: 10;
}
#user-stuff {
margin: 0px 0px 0px 0px;
padding: 40px 0px 20px 10px;
height: auto;
width: 400px;
z-index: 20;
}
z-index only works on positioned elements, so you need to add a position to your user-stuff div.
#user-stuff {
margin: 0px 0px 0px 0px;
padding: 40px 0px 20px 10px;
height: auto;
width: 400px;
position:relative;
z-index: 20;
}
jsFiddle example
There is no position in #user-stuff:
#user-stuff {
margin: 0px 0px 0px 0px;
padding: 40px 0px 20px 10px;
height: auto;
width: 400px;
z-index: 20;
position: relative;
}