Reputation: 27
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!
Upvotes: 0
Views: 8844
Reputation: 165
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);
}
Upvotes: 1
Reputation: 7291
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" />
Upvotes: 2
Reputation: 3815
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>
Upvotes: 3
Reputation: 115293
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>
Upvotes: 0