I am trying to replicate canvas frame effect on paintings on images using CSS.
I can do shadows and rounded corners but I couldn't figure out how to do the 3D effect of "rounded/wrapping sides".
My actual is left image while I am trying to replicate the effect of the right one. Please ignore the background of the expected image.
Any help?
Thanks.
.image{
display:flex;
justify-content:space-evenly;
}
#actual {
border-radius: 4px;
box-shadow: 20px 4px 10px rgba(0,0,0,0.35), 40px 8px 10px rgba(0,0,0,0.15);
}
<div class="image">
<img id="actual" src="http://lorempixel.com/output/cats-q-c-640-480-10.jpg">
<img id="expected" src="https://i.imgur.com/XD8Vdvv.jpg">
</div>
You can approximate it using inset shadow:
.image{
display:inline-block;
border-radius: 4px;
box-shadow:
-2px -2px 1px rgba(0,0,0,0.5) inset,
20px 4px 10px rgba(0,0,0,0.35),
40px 8px 10px rgba(0,0,0,0.15);
width:320px;
height:240px;
margin:10px;
background:url(http://lorempixel.com/output/cats-q-c-640-480-10.jpg) center/cover;
}
<div class="image">
</div>
Just want to get creative with box-shadow layering... Cheers;
figure {
display: block;
margin: 1rem auto;
height: 10rem;
width: 10rem;
border: gray 1px solid;
border-radius: 3px;
background: lightgray url('https://i.stack.imgur.com/BVW9D.jpg') no-repeat center center;
background-size: cover;
box-shadow: 2px 2px 0 gray,
3px 3px 4px rgba(0,0,0,.9),
6px 6px 12px 4px rgba(0,0,0,.25),
0 0 14px 4px rgba(0,0,0,.15);
}
<figure></figure>
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.
My question is how can I blur only the border of an image?
The image itself should not be blured, just the border.
EDIT: done..thanks!
You can do it by using box-shadow property like below
TIP: you need to match the shadow color to your background or image border for the desired effect.
.image-blurred-edge {
background-image: url('http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg');
width: 200px;
height: 200px;
box-shadow: 0 0 8px 8px #fff inset;
}
<div class="image-blurred-edge"></div>
Using img tag you have to use pseudo element that is :before
.shadow
{
display:inline-block;
position:relative;
width: 150px;
height: 150px;
}
.shadow:before
{
display:block;
content:'';
position:absolute;
width:100%;
height:100%;
-moz-box-shadow:inset 0px 0px 8px 4px #fff;
-webkit-box-shadow:inset 0px 0px 8px 4px #fff;
box-shadow:inset 0px 0px 8px 4px #fff;
}
<div class="shadow">
<img src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
</div>
Considering your last comment Try this solution.
.shadow img{
border:2px solid #000;
box-shadow:1px 1px 10px 2px;
}
<div class="shadow">
<img src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
</div>
Looking at your comments on Sagar Kodte's answer, is this what you wanted?
img {
border: 2px solid #000;
box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.8);
}
<img src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
I added a border of 2px to the images and a box shadow.
"Out there" idea:
I'll preface this by saying css variables are coming in fast but are not everywhere yet (Just IE lagging behind I think).
That being said I think they are a wonderful idea and will put this answer here just so you know of their existence.
.red {
--border-color: #900;
}
.green {
--border-color: #090;
}
.blue {
--border-color: #009;
}
.clown {
--border-color-top: green;
--border-color-right: yellow;
--border-color-bottom: red;
--border-color-left: blue;
}
img {
border-top: 2px solid var(--border-color-top, var(--border-color, #000));
border-bottom: 2px solid var(--border-color-bottom, var(--border-color, #000));
border-right: 2px solid var(--border-color-right, var(--border-color, #000));
border-left: 2px solid var(--border-color-left, var(--border-color, #000));
box-shadow: 0 -4px 10px -1px var(--border-color-top, var(--border-color, #000)), 4px 0 10px -1px var(--border-color-right, var(--border-color, #000)), 0 4px 10px -1px var(--border-color-bottom, var(--border-color, #000)), -4px 0 10px -1px var(--border-color-left, var(--border-color, #000));
margin: 10px;
}
.img {
border: 2px solid var(--border-color, #000);
box-shadow: 0 0 10px var(--border-color, #000);
margin: 10px;
}
<b>Standard:</b>
<br>
<img src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
<br>
<b>Single color:</b>
<br>
<img class="red" src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
<img class="green" src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
<img class="blue" src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
<br>
<b>Mulitple colors:</b>
<br>
<img class="clown" src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
HTML
<img class="borderBlur" src="http://visitwabashcounty.com/wp-content/uploads/6056710418_03fda4569b_z-150x150.jpg" />
CSS
.borderBlur {
border: 2px solid #000;
box-shadow: 0 0 15px 5px rgba(0, 0, 0, 0.8);
}
As long as you wrap the image in a div you can apply a box-shadow to that.
It will appear under the image to start, so you need to apply a lower z-index to the image
body {
text-align: center;
}
.img-wrap {
display: inline-block;
margin: 2em;
box-shadow: inset 0 0px 4px 4px black;
}
img {
display: block;
position: relative;
z-index: -1;
}
<div class="img-wrap">
<img src="http://www.fillmurray.com/284/196" alt="" />
</div>
I have a header, a sidebar, and a content div.
The Header is docked to the top and fixed there. The sidebar is fixed the to the left. Now I have 3/4 of the screen on the right free of space. I have a content div that I want to place there. It needs to be centered in that 3/4 space.
Here is my code for the sidebar and content div.
CSS:
html,body {
height:100%;
}
#sidebar {
float: left;
width: 300px;
background: #fff;
background: rgba(225,225,225,0.2);
height:100%;
}
#sidebarTop {
height:100%;
background-color: #eee;
padding:20px 50px;
border-bottom:0.15em solid rgb(229,229,229);
background: rgba(225,225,225,0.25);
box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
-o-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0px 1px rgba(255,255,255,0.3), inset 0px 0px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset -10px 0px 0px rgba(0,0,0,0.3);
-moz-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
}
#content {
margin: 0 auto;
display:block;
width:400px;
margin-top:100px;
height:900px;
background:#FFF;
-webkit-box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
-moz-box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
}
Here is my HTML code for sidebar and content div.
<div id="sidebar">
<div id="sidebarTop">
....
</div>
</div>
<div id="content">
TEST
</div>
The problem comes here. What happens is that instead of ignoring the sidebar and pushing the content div to 100px down (margin-top:100px), it brings the side-bar down to the same level too.
My goal is to center that div both vertically and horizontally in that 3/4 of screen space left after the sidebar and the header fill the rest.
Any help is much appreciated!
Add float:left; to #content.
#content {
margin: 0 auto;
width:400px;
margin-top:100px;
height:900px;
background:#FFF;
-webkit-box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
-moz-box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
}
should be:
#content
{
margin:100px auto 0;
width:400px;
height:900px;
background:#fff;
-webkit-box-shadow:0 0 30px #fff;
-moz-box-shadow:0 0 30px #fff;
box-shadow:0 0 30px #fff;
float:left;
}
Updated:
CSS
html,
body
{
height:100%;
}
#sidebar
{
position:fixed;
top:0;
left:0;
width:300px;
height:100%;
background-color:#758;
}
#content
{
margin-left:-50px;
position:absolute;
top:100px;
left:50%;
width:400px;
height:900px;
background:#758;
}
HTML
<div id="sidebar">
"fixed" sidebar
</div>
<div id="content">
"horizontally centered" content
</div>
DEMO
Update 2:
CSS
#wrapper
{
position:absolute;
top:100px;
left:300px;
right:0;
height:900px;
}
#content
{
margin:0 auto;
width:400px;
height:100%;
background:#758;
}
HTML
<div id="sidebar">
"fixed" sidebar
</div>
<div id="wrapper">
<div id="content">
"horizontally centered" content
</div>
</div>
DEMO 2
You could try in this way:
CSS:
html,body {
height:100%;
}
#sidebar {
border: 2px solid yellow; /*Added to show the box-model*/
float: left;
width: 25%;
background: #fff;
background: rgba(225,225,225,0.2);
height:100%;
}
#sidebarTop {
border: 2px solid black; /*Added to show the box-model*/
height:100%;
background-color: #eee;
padding:20px 50px;
border-bottom:0.15em solid rgb(229,229,229);
background: rgba(225,225,225,0.25);
box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
-o-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0px 1px rgba(255,255,255,0.3), inset 0px 0px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset -10px 0px 0px rgba(0,0,0,0.3);
-moz-box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
}
#foo {
border: 2px solid pink; /*Added to show the box-model*/
margin-top: 100px;
margin-left: 27%;
width: 73%;
}
#content {
border: 2px solid green; /*Added to show the box-model*/
margin: 0 auto;
display:block;
width:400px;
/*margin-top:100px;*/ /*this can be deleted*/
height: 100%;
background:#FFF;
-webkit-box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
-moz-box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
box-shadow: 0px 0px 30px rgba(255, 255, 255, 1);
}
And HTML:
<div id="sidebar">
<div id="sidebarTop">
....
</div>
</div>
<div id="foo">
<div id="content">
TEST
</div>
</div>
#sidebarTop {
margin: 0 auto;
}
You can simply use "center" tag like this:
<div id="content">
<center>
TEST
</center>
</div>
I have two divs next to the each other which background color is white. http://jsfiddle.net/J5ZXt/ is link to code. I want that two divs look like one element, so I need to remove a part of shadow. Any ideas?
Yes, it is possible. Simply cover it up with :before:
/* Add relative positioning */
#two {
position:relative;
}
/* Add :before element to cover up shadow */
#two:before {
background:white;
display:block;
content:".";
font-size:0;
width:4px;
height:100px;
position:absolute;
left:-4px;
top:0;
}
/* Existing styles */
#one {
width: 100px;
height: 100px;
background: #FFF;
-moz-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
float:left;
}
#two {
width: 100px;
height: 300px;
background: #FFF;
-moz-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
float:left;
}
<div id="one"></div>
<div id="two"></div>
This is the best I could get within a couple of minutes, I think it does the job. The best thing is its simplicity (only 3 edits to your css)
Position D1's shadow so the right edge has a negative value (-4px is enough to hide it)
Give both divs relative positioning so we can control their stacking order.
Give D1 a higher z-index than D2 so it masks the top part of D2's shadow.
#one {
width: 100px;
height: 100px;
background: #FFF;
-moz-box-shadow: -4px 0 3px 1px rgba(0,0,0,0.3);
-webkit-box-shadow: -4px 0 3px 1px rgba(0,0,0,0.3);
box-shadow: -4px 0px 3px 1px rgba(0,0,0,0.3);
float:left;
position: relative;
z-index: 20;
}
#two {
width: 100px;
height: 300px;
background: #FFF;
-moz-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
float:left;
z-index: 5;
position: relative;
}
Pure CSS - no
You could always try absolutely position a div above it, as in this example
The ::before solution does not work in all browsers
Because I hate to be outdone and tend to be a perfectionist, I came up with an answer that doesn't rely on a specific height for #one--it just has to be shorter than #two (which is also the case for the currently accepted answer). It also does not have the downside of a gap or larger shadow on one side of #one.
Note: This answer also gives the possibility for a curved corner via border-radius. Simply add border-radius:4px; to #one:after to see the result.
jsFiddle Example
New CSS
<style type="text/css">
#one {
width: 100px;
height: 200px;
background: #fff;
float:left;
position:relative;
overflow:hidden;
}
#one:after {
display:block;
content:".";
font-size:0;
color:transparent;
height:8px;
width:100%;
padding-left:4px;
position:absolute;
bottom:-4px;
left:-4px;
background:#fff;
z-index:2;
-moz-box-shadow: inset 0 0 3px 1px rgba(0,0,0,0.3);
-webkit-box-shadow: inset 0 0 3px 1px rgba(0,0,0,0.3);
box-shadow: inset 0 0 3px 1px rgba(0,0,0,0.3);
}
#two {
width: 100px;
height: 300px;
background: #FFF;
-moz-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
-webkit-box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
float:left;
}
</style>