I want to have inner shadow only on bottom semicircle of my circular div but shadow seems moving on wrong edges.
Js Fiddle
important part from code which does not work:
box-shadow: inset 3px 3px 3px -1px #000;
What I want is slightly different from those in fiddle :
Some may call this as an inset shadow.
that's what you mean:
.floating-circle{
border-radius: 50%;
background-color: blue;
width: 100px;
padding-top: 100px;
position: absolute;
box-shadow: inset 0 -3px 3px #000;
}
edit, so maybe like this, but without blur:
.floating-circle{
border-radius: 50%;
background-color: #00008B;
width: 100px;
padding-top: 100px;
position: absolute;
overflow: hidden;
}
.floating-circle::after{
border-radius: 50%;
background-color: blue;
width: 100px;
padding-top: 100px;
content:'';
position: absolute;
bottom:5px;
left:0;
}
main element should be "shadow" color, pseudo element should be your main color
3rd try :P with blur, of course You can manipulate blur amount, pesudo element width/height and position to achiver right amount of inner shadow:
.floating-circle{
border-radius: 50%;
background-color: #00008B;
width: 200px;
height: 200px;
position: absolute;
overflow: hidden;
}
.floating-circle::after{
border-radius: 50%;
width: 220px;
height: 220px;
content:'';
position: absolute;
bottom:-5px;
left:-10px;
box-shadow: inset 0 -20px 10px rgba(0,0,0,0.5);
}
i'am afraid there always be some little artifacts, but there are some technics that can make them less visible, translateZ(0) or something like that - try it yourself :)
edit, with percent values:
.floating-circle{
border-radius: 50%;
background-color: #00008B;
width: 70%; /*can be %/px/vw or anything else */
height: 70%; /*can be %/px/vw or anything else */
position: absolute;
overflow: hidden; /*disable this to better see what exactly is happeing with shadow*/
}
.floating-circle::after{
border-radius: 55%;
width: 110%;
height: 110%;
content:'';
position: absolute;
bottom:-5%;
left:-5%;
box-shadow: inset 0 -20px 10px rgba(0,0,0,0.5);
}
you can now set .floatin-circle width/height to percent value or pixels value, and shadow should always work pretty good - you can "tweak" amount of shadow, by rgba opacity color or moving it up and down with "bottom" value or play with box-shadow props :)
Related
I am trying to create a box-shadow with two different colours horizontally of a line. Is there any way to do it instead of box-shadow? I am trying to build the inner design of the screen.
.neon-rod
{
position: relative;
height: 0.2vmin;
width: 25vmin;
background: red;
left: 50vmin;
box-shadow:
0.2vmin 0 0 0.1vmin #69e;
}
<div class="neon-rod"></div>
Reference Image
Above is the reference image of the design.
Codepen:- https://codepen.io/himanshu-pal/pen/vYejNZW
I have increased the blur and spread of box-shadow property
.neon-rod
{
position: relative;
height: 5px;
width: 100px;
background: red;
left: 50vmin;
box-shadow:
0 0 8px 4px #69e;
}
<div class="neon-rod"></div>
With :before
.neon-rod {
position: relative;
height: 5px;
width: 100px;
background: #69e;
left: 50vmin;
box-shadow: 0 0 8px 4px #69e;
}
.neon-rod:before {
content: "";
position: absolute;
width: 90%;
background: #0f0;
left: 5px;
right: 5px;
top: 3px;
bottom:3px;
box-shadow: 0 0 3px 2px #0f0;
}
<div class="neon-rod"></div>
More details:
https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
You can add more than one box-shadow and use different colors for each. Just separate the shadows with a comma.
.neon-rod
{
position: relative;
height: 1vmin;
width: 25vmin;
background: red;
left: 50vmin;
top: 10vmin;
box-shadow:
0.2vmin 0.3vmin 1.6vmin #69e8,
0.3vmin 0.4vmin 3.2vmin #69ea,
0.3vmin 0.4vmin 4.8vmin #69ec,
0.3vmin 0.4vmin 6.4vmin #69ef,
-0.2vmin -0.3vmin 0.8vmin green;
}
<div class="neon-rod"></div>
I've been trying to create elements which will change position slightly when hovered - in this example we have a primitive attempt at a 3D button which is slightly depressed when hovered over. All works as intended, unless the top and left 3 pixels are hovered over, in which case it rapidly flickers between the two states.
Is it possible, without creating a duplicate transparent element, to make the hover area not shift with the element and eliminate this behaviour? JavaScript and JQuery solutions are okay but pure HTML/CSS would be best.
#button {
width: 100px;
height: 100px;
background-color: #00f;
box-shadow: 10px 10px 3px #aaa;
}
#button:hover {
transform: translate(3px, 3px);
box-shadow: 7px 7px 2.1px #888;
}
<div id="button">
</div>
JSFiddle link
You could create a pseudo element :after and style this instead:
#button {
width: 100px;
height: 100px;
}
#button:after {
display: block;
width: 100%;
height: 100%;
background-color: #00f;
box-shadow: 10px 10px 3px #aaa;
content: "";
}
#button:hover:after {
transform: translate(3px, 3px);
box-shadow: 7px 7px 2.1px #888;
}
<div id="button">
</div>
You can use a relative position and left/top offsets instead, that seems to work better (i.e. without flickering):
#button {
width: 100px;
height: 100px;
background-color: #00f;
box-shadow: 10px 10px 3px #aaa;
position: relative;
}
#button:hover {
left: 3px;
top: 3px;
box-shadow: 7px 7px 2.1px #888;
}
<div id="button">
</div>
Is it possible to make a div same as this shape, if yes could you please share the code
I would use SVG: http://codepen.io/anon/pen/JdMVXY
<svg>
<path d="M260 150, 0 150, 0 0, 300 0 Q260 75, 260 150"
stroke="transparent" fill="#bd9" />
</svg>
When you have defined the correct aspect ratio of the box, you can also scale the SVG element with a simple CSS transformation (as shown in the example)
Result
This is possible within CSS using a single element with pseudo-elements with border-radius and background-shadow to create the curve.
div {
height: 100px;
width: 300px;
position: relative;
overflow: hidden;
}
div:before {
content: '';
position: absolute;
top: -150%;
left: 50%;
width: 200%;
padding-bottom: 200%;
border-radius: 100%;
background: none;
-webkit-box-shadow: 0px -10px 5px 300px #F15723;
box-shadow: 0px -10px 5px 300px #F15723;
z-index: -1;
}
<div></div>
Try this to make 'div' element:
<div id="test">
<div class="oposite-radius"></div>
<style>
#test {
position: relative;
margin: 30px;
width: 200px;
height: 100px;
border: 1px solid #333;
}
.oposite-radius {
position: absolute;
height: 100px;
width: 20px;
border: 1px solid #333;
background-color: #fff;
left: 180px;
border-radius: 100% 0 0 0;
border-width: 1px 0 0 1px;
}
</style>
I have a slider on my page to change the box-shadow values. At some high blurring values there is an unwanted box-like breaking the shadow, when it is supposed to be a smooth shadow all the way. Is there anyway to avoid this easily? Thanks for the help.
P. S.
I actually need it to work with 'inset' too.
div
{
width:200px;
height:200px;
border-radius: 100px;
background-color:blue;
-webkit-box-shadow: 169px 129px 300px -15px rgba(0,0,0,1);
-moz-box-shadow: 169px 129px 300px -15px rgba(0,0,0,1);
box-shadow: 169px 129px 300px -15px rgba(0,0,0,1);
}
<div></div>
For circular box-shadows the blur cannot go above the width & height of the element. The spread can though.
Since your element is 200px * 200px, the maximum for the blur value is 200px.
Have a look below at the example which doesn't go above 200px and you will see that it creates the box-shadow as expected
div {
width: 200px;
height: 200px;
border-radius: 100px;
background-color: blue;
box-shadow: 169px 129px 200px -15px rgba(0, 0, 0, 1);
}
<div></div>
The spread value can alternatively go above the element width and height and therefore you can make bigger spreads.
div {
width: 200px;
height: 200px;
border-radius: 100px;
background-color: blue;
box-shadow: 169px 129px 0 250px rgba(0, 0, 0, 1);
}
<div></div>
You also didn't really need the prefixes since CSS3 Box-shadows are very well supported now. CanIUse
You can read more about CSS Box shadows in the MDN Documentation
If you want to go outside its dimensions on the shape to be blurred:
The code creates a copy of the circle then colours it black and uses the filter:blur(length);
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
position: relative;
}
.circle::after {
position: absolute;
display: block;
content: " ";
border-radius: 50%;
width: 100%;
height: 100%;
background-color: blue;
}
.circle::before {
position: absolute;
display: block;
content: " ";
border-radius: 50%;
width: 100%;
height: 100%;
background-color: black;
top: 50%;
left: 50%;
-webkit-filter: blur(50px);
filter: blur(50px);
}
<div class="circle"></div>
You can also create inset shadows this way.
How it works:
1. The initial shape is the shadow-color
2. Set overflow:hidden so nothing goes outside the shape.
3. Put a shape on top
4. Blur the shape on top
By doing this the shape under shines through creating the inner shadow effect
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
position: relative;
background-color: black;
overflow: hidden;
}
.circle::before {
position: absolute;
display: block;
content: " ";
border-radius: 50%;
width: calc(100%);
height: calc(100%);
background-color: blue;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
-webkit-filter: blur(20px);
filter: blur(20px);
}
<div class="circle"></div>
I am trying to achieve this effect where a photo gets a repeating pattern overlayed over the entire photo when the user place his mouse over the photo.
Problem: I do not seem to be able to make the overlay div overlay the photo completely. How should this be done?
JSfiddle: http://jsfiddle.net/KDyKH/2/
Edit: Updated the fiddle
CSS
#container {
position: relative;
padding: 10px;
width: 1000px;
height: 500px;
background: blue;
}
.photo_box {
padding: 8px 10px 11px 10px;
background: #fff;
-webkit-box-shadow: 1px 1px 6px rgba(50, 50, 50, 0.25);
-moz-box-shadow: 1px 1px 6px rgba(50, 50, 50, 0.25);
box-shadow: 1px 1px 6px rgba(50, 50, 50, 0.25);
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
display: inline-block;
position: relative;
}
.photo {
position: absolute;
z-index: 0;
margin-bottom: 13px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.photo_tint {
width: 100%;
height: 100%;
position: absolute;
z-index: 100;
background: red;
-moz-opacity: 0.70;
opacity: 0.70;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha"(Opacity=70);
}
HTML
<div id="container">
<div class="photo_box">
<img src='http://www.kurzweilai.net/images/Google-logo.jpg' class="photo">
<div class="photo_tint"></div>
</img>
</div>
</div>
In addition to adding left and top properties to .photo_tint, you also need to make .photo_box relatively positioned (it wasn't before you edited your question).
.photo_box {
position: relative;
}
.photo_tint {
left:0;
right:0;
}
http://jsfiddle.net/KDyKH/5/
The absolute position's left/top/right/bottom attributes work off the last element higher in the hierarchy with position set to relative or absolute. If no parent elements have position set to relative/absolute, the body is used. In your case, the closest relatively positioned element was #container, so when left and top were set on .photo_tint it used #container's origin and not .photo_box's origin as needed to achieve the desired effect.
Additionally, if an element is set to position:absolute, and no left/top/right/right properties are set, the element will not behave as absolute (see this question).
.photo_tint {
position: absolute;
z-index: 100;
background: red;
top:0; left:0;
width:100%; height:100%;
}
???
http://jsfiddle.net/tFbbM/1/
Just position the photo_tint div using top and left. http://jsfiddle.net/OhMrBigshot/gEdJu/
z-index:-1 on the image or z-index:2 on the div
#container {
position: relative;
width: 500px;
height: 500px;
background: blue;
}
.photo {
position: relative;
width: 300px;
height: 100px;
background: green;
}
.photo_tint {
position: absolute;
z-index: 1;
background: red;
width: 300px;
height: 100px;
top:0px;
}