Greetings,
I am trying to apply a CSS3 box shadow to only the top, right, and left of a DIV with a radius that matches the result of the following CSS (minus the bottom shadow)
#div {
-webkit-box-shadow: 0px 0px 10px #000;
-moz-box-shadow: 0px 0px 10px #000;
box-shadow: 0px 0px 10px #000;
}
What would be the best way to accomplish this?
Thanks!
UPDATE
This shadow will be applied to a nav bar on a page, the bar is positioned on the top of the main container DIV. What I am trying to accomplish is to continue the box shadow of the main DIV onto the nav bar, which sits above it, but without a bottom shadow on the nav bar. Take a look at the site itself to see what I'm talking about, easier than adding all of the HTML and CSS here.
UPDATE 2
Since the DIV I am working with is singular, rather than trying to place a shadow on each nav li, I elected to change it to the following:
-webkit-box-shadow: 0px -4px 7px #e6e6e6;
-moz-box-shadow: 0px -4px 7px #e6e6e6;
box-shadow: 0px -4px 7px #e6e6e6;
This makes the top of the shadow very noticeable but it's what I am trying to accomplish - if anyone knows of a way to keep the shadow the same in appearance to the container DIV, please let me know. Thanks!
use the spread value...
box-shadow has the following values
box-shadow: x y blur spread color;
so you could use something like..
box-shadow: 0px -10px 10px -10px black;
UPDATE: i'm adding a jsfiddle
It's better if you just cover the bottom part with another div and you will get consistent drop shadow across the board.
#servicesContainer {
/*your css*/
position: relative;
}
and it's fixed! like magic!
You can give multiple values to box-shadow property
eg
-moz-box-shadow: 0px 10px 12px 0px #000,
0px -10px 12px 0px #000;
-webkit-box-shadow: 0px 10px 12px 0px #000,
0px -10px 12px 0px #000;
box-shadow: 0px 10px 12px 0px #000,
0px -10px 12px 0px #000;
it is drop shadow to left and right only, you can adapt it to your requirements
I found a way to cover the shadow with ":after", here is my code:
#div:after {
content:"";
position:absolute;
width:5px;
background:#fff;
height:38px;
top:1px;
right:-5px;
}
The following code did it for me to make a shadow inset of the right side:
-moz-box-shadow: inset -10px 0px 10px -10px #000;
-webkit-box-shadow: inset -10px 0px 10px -10px #000;
box-shadow: inset -10px 0px 10px -10px #000;
Hope it will help!!!!
I was having the same issue and was searching for a possible idea to solve this.
I had some CSS already in place for my tabs and this is what worked for me:
(Note specifically the padding-bottom: 2px; inside #tabs #selected a {. That hides the bottom box-shadow neatly and worked great for me with the following CSS.)
#tabs {
margin-top: 1em;
margin-left: 0.5em;
}
#tabs li a {
padding: 1 1em;
position: relative;
top: 1px;
background: #FFFFFF;
}
#tabs #selected {
/* For the "selected" tab */
box-shadow: 0 0 3px #666666;
background: #FFFFFF;
}
#tabs #selected a {
position: relative;
top: 1px;
background: #FFFFFF;
padding-bottom: 2px;
}
#tabs ul {
list-style: none;
padding: 0;
margin: 0;
}
#tabs li {
float: left;
border: 1px solid;
border-bottom-width: 0;
margin: 0 0.5em 0 0;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
Thought I'd put this out there as another possible solution for anyone perusing SO for this.
I know this is very old, but none of these answers helped me, so I'm adding my answer. This, like #yichengliu's answer, uses the Pseudo ::after element.
#div {
position: relative;
}
#div::after {
content: '';
position: absolute;
right: 0;
width: 1px;
height: 100%;
z-index: -1;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,1);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,1);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,1);
}
/*or*/
.filter.right::after {
content: '';
position: absolute;
right: 0;
top: 0;
width: 1px;
height: 100%;
background: white;
z-index: -1;
-webkit-filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 1));
filter: drop-shadow(0px 0px 1px rgba(0, 0, 0, 1));
}
Fiddle
If you decide to change the X of the drop shadow (first pixel measurement of the drop-shadow or box-shadow), changing the width will help so it doesn't look like there is a white gap between the div and the shadow.
If you decide to change the Y of the drop shadow (second pixel measurement of the drop-shadow or box-shadow), changing the height will help for the same reason as above.
I fixed such a problem by putting a div down the nav link
<div [ngClass]="{'nav-div': tab['active']}"></div>
and giving this css to it.
.nav-div {
width: inherit;
position: relative;
height: 8px;
background: white;
top: 4px
}
and nav link css as
.nav-link {
position: relative;
top: 8px;
&.active {
box-shadow: rgba(0, 0, 0, 0.3) 0 1px 4px -1px;
}
}
Hope this helps!
Adding a separate answer because it is radically different.
You could use rgba and set the alpha channel low (to get transparency) to make your drop shadow less noticeable.
Try something like this (play with the .5)
-webkit-box-shadow: 0px -4px 7px rbga(230, 230, 230, .5);
-moz-box-shadow: 0px -4px 7px rbga(230, 230, 230, .5);
box-shadow: 0px -4px 7px rbga(230, 230, 230, .5);
Hope this helps!
#div:before {
content:"";
position:absolute;
width:100%;
background:#fff;
height:38px;
top:1px;
right:-5px;
}
Related
I want to make box-shadow to the left and right sides,however there is alway a shadow in the top of the box,I have checked my code many times.
#box {
margin: 0 auto;
margin-top: 0px;
border: 1px solid #ffffff;
border-top-color: #e99f2e;
overflow: hidden;
box-shadow: 2px 0 20px 2px #7f7e7f, -2px 0 20px 2px #7f7e7f;
}
<div id="box"></div>
First understand the syntax of box-shadow and then it get's easy to apply box-shadow at any side as you have planned your design,
syntax -
box-shadow : offset-x | offset-y | blur-radius | spread-radius | color
#box {
margin: 0 auto;
margin-top: 0px;
overflow: hidden;
box-shadow: -10px 0 2px -2px #7f7e7f, 10px 0 2px -2px #7f7e7f;
height: 150px;
width: 50%;
background:#cff;
margin-top:20px;
}
<div id="box"></div>
There is a hack actually.
You can achieve this by adding an "empty" top and bottom shadow.
box-shadow: 0 9px 0px 0px white, 0 -9px 0px 0px white, 12px 0 15px -4px rgba(30, 53, 125, 0.9), -12px 0 15px -4px rgba(30, 53, 125, 0.9);
I don't think this is as good as the other answers, but this is an alternative approach using absolute positioned pseudo elements with shadows.
.lr-shadow {
background:#fff;
border: 1px solid #fff;
border-top-color: #e99f2e;
width:100%;
max-width:500px;
height:200px;
position:relative;
margin:0 auto;
}
.lr-shadow:before, .lr-shadow:after {
box-shadow: 0 0 20px 2px #7f7e7f;
content:" ";
position:absolute;
top:50%;
transform:translateY(-50%);
height:90%;
z-index:-1;
}
.lr-shadow:before {
left:5px;
}
.lr-shadow:after {
right:5px;
}
<div class="lr-shadow"></div>
You can achieve this effect if you set the spread to the negative of blur parameter. For the left box shadow, set position to negative blur and the right box shadow, position to positive blur. I used 20px in this demo:
#box {
margin: 0 auto;
margin-top: 40px;
border: 1px solid #ffffff;
border-top-color: #e99f2e;
overflow: hidden;
width: 150px;
height: 150px;
box-shadow: 20px 0px 20px -20px #7f7e7f, -20px 0px 20px -20px #7f7e7f;
}
<div id="box"></div>
Check out this CSS Box-shadow generator to explore further.
Alright, I know that this question has been asked before, but I have a kind of different CSS and the effect is different too. My CSS:
div.side-bar {
text-align: right;
width: 11%;
margin-left: 88%;
border-left: 1px solid #000;
position: fixed;
height: 88%;
-webkit-box-shadow: -5px 0px 5px 0px #616161;
box-shadow: -5px 0px 5px 0px #616161;
}
So using the following code gives me a shadow to the left side as I wanted, but it also adds small shadows to both top and bottom sides too. How to have a shadow only on the left side?
Try changing your box-shadow property by adding a negative spread radius like this: http://jsfiddle.net/vW8VS/3/
div.side-bar {
text-align: right;
width: 11%;
margin-left: 88%;
border-left: 1px solid #000;
position: fixed;
height: 88%;
-webkit-box-shadow: -5px 0px 5px -3px #616161;
box-shadow: -5px 0px 5px -3px #616161;
}
That should let you push it off to just one side without worrying about the top and bottom.
I found to get the proper box-shadow effect to the left side of a div only I had to play around more with the css. use the below styles, they worked great for what I was trying to achieve.
-webkit-box-shadow: -35px 0px 20px -35px #aaa;
box-shadow: -35px 0px 20px -35px #aaa;
Hi I have a div at the top of my page
http://www.uk-sf.com/MyTraining.php
the box-shadow is cut on the wrapper, I tried giving it a z-index but no joy any ideas?
.titlebox{
width:977px;
background-color:rgba(48, 48, 48, 1);
padding:10px 5px;
margin: 5px 5px;
font-size: 24px;
border:3px double rgb(138, 138, 138);
-webkit-box-shadow: 0px 0px 51px 7px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 51px 7px rgba(0,0,0,0.75);
box-shadow: 0px 0px 51px 7px rgba(0,0,0,0.75);
}
Help appreciated
Your #contentContainer has overflow:auto; : is it on purpose?
If not, add this to your CSS :
#contentContainer {
overflow: visible;
}
or just delete the overflow:auto declaration from your CSS.
(overflow: auto is asking your contentContainer to clip its content.)
I'm attempting to use a dark shadow color on three sides of a div, and a light "glow" on one side -- essentially using two different colors for the CSS box shadow. So far the best solution I've come up with is to place a shadow on all sides but one, and use a second div with a glow, and a third div to hide the glow on all but one side with margins and overflow-hidden. I was just wondering if there might be a better (CSS-only) method than the one I'm implementing? Any ideas?
Demo here - http://swanflighthaven.com/css-shadow-glow.html
It doesn't look nearly as nice on a light background:
http://swanflighthaven.com/css-shadow-glow2.html
#main {
max-width:870px;
min-width:610px;
margin:0px auto;
position:relative;
top:40px;
min-height:400px;
}
#maininside {
position:relative;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
overflow:hidden;
padding:0px 25px 25px 25px;
}
#maininner {
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
overflow:hidden;
box-shadow: 0px 0px 28px rgba(0, 0, 0, 0.80);
-moz-box-shadow: 0px 0px 28px rgba(0, 0, 0, 0.80);
-webkit-box-shadow: 0px 0px 28px rgba(0, 0, 0, 0.80);
min-height:385px;
padding:0px 15px 15px 15px;
background:url(center.png) repeat;
}
#glow {
position:absolute;
height:50px;
top:0px;
box-shadow: 0 -10px 20px -5px #7b272c;
-moz-box-shadow: 0 -10px 20px -5px #7b272c;
-webkit-box-shadow: 0 -10px 20px -5px #7b272c;
display: block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-right:25px;
margin-left:25px;
margin-bottom:25px;
}
<div id="main">
<div id="glow">
</div>
<div id="maininside">
<div id="maininner" ></div>
</div>
</div>
You can just write multiple shadows, comma separated:
{
box-shadow: 0px 0px 28px rgba(0, 0, 0, 0.80), 0 -10px 20px -5px #7b272c;
}
See https://developer.mozilla.org/En/CSS/Box-shadow
try negative spread values in the box-shadow css
Instead of creating the second div with the fancy margins and the hiding, try to play around with a negative spread value. It reduces the bleeding on the sides that you don't want your shadow to show up on. Play around with the example on my jsfiddle, set the spread to 0, -10, -5... you'll get the hang of it quick.
#glow {
/* x y blur spread color */
box-shadow: /* ie */
0px -10px 15px -6px rgba(255,000,000,0.7), /* top - THE RED SHADOW */
0px 5px 15px 0px rgba(000,000,000,0.3), /* bottom */
5px 0px 15px 0px rgba(000,000,000,0.3), /* right */
-5px 0px 15px 0px rgba(000,000,000,0.3); /* left */
-webkit-box-shadow:
0px -10px 15px -7px rgba(000,255,000,0.7), /* top - THE RED SHADOW */
0px 5px 15px 0px rgba(000,000,000,0.3), /* bottom */
5px 0px 15px 0px rgba(000,000,000,0.3), /* right */
-5px 0px 15px 0px rgba(000,000,000,0.3); /* left */
-moz-box-shadow:
0px -9px 10px -8px rgba(000,000,255,0.9), /* top - THE RED SHADOW */
0px 5px 10px 0px rgba(000,000,000,0.3), /* bottom */
5px 0px 10px 0px rgba(000,000,000,0.3), /* right */
-5px 0px 10px 0px rgba(000,000,000,0.3); /* left */
}
body {
padding: 10%;
background-color: #fefefe;
}
div {
height: 300px;
width: 300px;
margin: 0px auto;
border-radius: 2pt;
border: 1px solid rgba(0,0,0,0.8);
background-color: #fefefe;
}
<div id="glow"></div>
I had to play around with the properties a bit to get them to look similar in the different browsers. Mozilla/FF was the biggest pain. Look at how much the values differ... it's kind of a tedious game of cat and mouse off-setting the blur with spread...
box-shadow is used in IE.
webkit is used in Chrome.
moz is used in Firefox.
http://jsfiddle.net/CoryDanielson/hSCFw/
I'm wondering about the support for side specific inner shadows in css3.
I know this works great on supported browsers.
div { box-shadow:inset 0px 1px 5px black; }
I'm just curious as to whether there is a way to achieve something like:
div { box-shadow-top:inset 0px 1px 5px black; }
This is what worked for me:
box-shadow: inset 1px 4px 9px -6px;
Example: http://jsfiddle.net/23Egu/
I don't think your really need box-shadow-top because if you set offsetx to 0 and offsety to any positive value only remaining shadow is on top.
if you want to have shadow on top and shadow in the bottom you just can simply use two divs:
<div style="box-shadow:inset 0 1px 5px black;">
<div style="box-shadow:inset 0 -1px 5px black;">
some content
</div>
</div>
if you want to get rid of shadow on sides use rgba instead of hex color and set bigger offsety:
box-shadow:inset 0 5px 5px rgba(0,0,0,.5)
this way you give shadow more opacity so sides stay hidden and with more offset you get less opacity
full example:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css">
body {
background: #1C1C1C;
}
div {
margin: 50px auto;
width: 200px;
height: 200px;
background: #fff;
-webkit-border-radius: 20px;
-khtml-border-radiust: 20px;
-moz-border-radius: 20px;
-o-border-radius: 20px;
border-radius: 20px;
box-shadow:inset 0px 5px 5px rgba(0,0,0,.5);
}
div > div {
background:none;
box-shadow:inset 0px -5px 5px rgba(0,0,0,.5);
}
</style>
</head>
<body>
<div><div></div></div>
</body>
</html>
using :before and after elements with regular shadows cut of by overflow:hidden on the parent box like in this example: http://dabblet.com/gist/2585782
CSS
/**
* Top and Bottom inset shadow
*/
#element{
background-color: #E3F2F7;
height: 55px;
position: relative; /* to position pseudo absolute*/
overflow: hidden; /* to cut of overflow shadow*/
margin-top: 200px;
}
#element:before , #element:after{
content: "\0020";
display: block;
position: absolute;
width: 100%;
height: 1px; /* when 0 no shadow is displayed*/
box-shadow: #696c5c 0 0 8px 0;
}
#element:before { top: -1px} /* because of height: 1*/
#element:after { bottom: -1px} /* because of height: 1*/
HTML
<div id="element"></div>
You can use a background gradient for a work around in most cases:
SCSS(with compass) example:
#include background(linear-gradient(top, #666 1%, #999 3%, #ddd 6%, #f6f6f6 9%, #f6f6f6 92%, #ddd 94%, #999 97%, #666 99%) );
box-shadow: inset 5px 0 5px -5px rgba(0,0,0,0.5),inset -5px 0 5px -5px rgba(0,0,0,0.5);
-moz-box-shadow: inset 5px 0 5px -5px rgba(0,0,0,0.5),inset -5px 0 5px -5px rgba(0,0,0,0.5);
-webkit-box-shadow: inset 5px 0 5px -5px rgba(0,0,0,0.5),inset -5px 0 5px -5px rgba(0,0,0,0.5);
-o-box-shadow: inset 5px 0 5px -5px rgba(0,0,0,0.5),inset -5px 0 5px -5px rgba(0,0,0,0.5);
This works just lovely :)
Here is a codepen illustrating it:
http://codepen.io/poopsplat/pen/cGBLy
For the same shadow but only on the top :
box-shadow: inset 0px 6px 5px -5px black;
To have the shadow in one direction you have to negate the "blur" parameter with the "spread" parameter and then adjust the "h-pos" and/or "v-pos" parameters by this same value.
It doesn't work with opposite border or triple border. You have to add one more definition.
More examples here : http://codepen.io/GBMan/pen/rVXgqP
No, not directly, but you can crop off the parts that you don't want by putting it in a div with overflow: hidden:
http://jsfiddle.net/Vehdg/
I just had this problem myself. The solution that I found was with multiple box-shadows (one for each side that you want your shadow). Here is the definition:
box-shadow: none|h-offset v-offset blur spread color |inset|initial|inherit;
Here is how to think it:
first, make the spread 0 (this will disable the effect on all sides)
the h-offset (if you set it to be positive, it will cast on the left side, if you set it negative, on the right side)
the v-offset (if you set it to be positive, it will cast on the top side, if you set it negative, on the bottom side
Here you can see my case with box-shadow on three sides (left, top, right and the bottom is with same color as the background to create the effect that I wanted - the left side and the right go all the way to the bottom)
https://codepen.io/cponofrei/pen/eMMyQX
You can accomplish a single-sided, inner shadow by setting your div to overflow:hidden and adding shadow elements along the borders.
Set an inner shadow on the top and bottom borders of a division:
HTML
<div id="innerShadow">
<div id="innerShadowTop">
Content...
<div id="innerShadowBottom">
</div>
CSS
#innerShadow
{
position: relative;
overflow: hidden;
}
#innerShadowTop
{
width: 100%;
height: 1px;
margin: 0;
padding: 0;
position: absolute;
top: -1px;
-moz-box-shadow: 0px 1px 6px 1px rgba(0, 0, 0, 0.65);
-webkit-box-shadow: 0px 1px 6px 1px rgba(0, 0, 0, 0.65);
-o-box-shadow: 0px 1px 6px 1px rgba(0, 0, 0, 0.65);
box-shadow: 0px 1px 6px 1px rgba(0, 0, 0, 0.65);
}
#bannerShadowBottom
{
width: 100%;
height: 1px;
margin: 0;
padding: 0;
position: absolute;
bottom: -1px;
-moz-box-shadow: 0px -1px 6px 1px rgba(0, 0, 0, 0.65);
-webkit-box-shadow: 0px -1px 6px 1px rgba(0, 0, 0, 0.65);
-o-box-shadow: 0px -1px 6px 1px rgba(0, 0, 0, 0.65);
box-shadow: 0px -1px 6px 1px rgba(0, 0, 0, 0.65);
}
box-shadow is for all four sides. You can't change that (yet?). The 4 sizes in the box-shadow definition are OffsetX, offsetY, Blur and Spread.
Multiple box shadows did the trick for me.
box-shadow:
inset 0 -8px 4px 4px rgb(255,255,255),
inset 0 2px 4px 0px rgba(50, 50, 50, 0.75);
http://jsfiddle.net/kk66f/