1

I am attempting to create an inner border to an image using box-shadow. I'm using code I copied from a CSS generator and it does not work on my image. How can I get this code to work with my image?

I am trying to make a top and a bottom border only. No sides.

http://codepen.io/trevoray/pen/NPxyzG

.bannerImages {
 -webkit-box-shadow: inset 0px -17px 0px 0px rgba(0, 0, 0, 1);
 -moz-box-shadow: inset 0px -17px 0px 0px rgba(0, 0, 0, 1);
 box-shadow: inset 0px -17px 0px 0px rgba(0, 0, 0, 1);
}
<img class="bannerImages" src="http://webtest-community.canoo.com/wiki/space/SnipSnap/config/webtest_tag_rgb_pos_small.jpg" />

asked Dec 8, 2014 at 17:16
4
  • Whyt not user border: 1px solid #000 and box-sizing: border-box? Commented Dec 8, 2014 at 17:19
  • See- designbystevie.com/2011/03/… Commented Dec 8, 2014 at 17:23
  • Paulie_D, I'm attempting to create only top and bottom border. Commented Dec 8, 2014 at 18:01
  • Are you actually creating a box shadow, or are you just wanting a solid border that overlaps the image? If it's the latter, you might want to consider different approach; Farhan's box-shadow solution can easily be adjusted to work with just borders. :) Commented Dec 9, 2014 at 10:22

3 Answers 3

4

You can use outline to get a border inside the image

.bannerImages {
 outline: 1px solid red;
 outline-offset: -4px; 
}
<img class="bannerImages" src="http://webtest-community.canoo.com/wiki/space/SnipSnap/config/webtest_tag_rgb_pos_small.jpg" />

More info: http://caniuse.com/#search=outline

answered Dec 8, 2014 at 17:30
Sign up to request clarification or add additional context in comments.

1 Comment

I can't use outline because I want a top and bottom border. Not an entire border.
1

Here's how. The trick is to wrap your image in another element and use an absolutely positioned before pseudo-element.

Jordan Gray
16.5k3 gold badges56 silver badges70 bronze badges
answered Dec 8, 2014 at 17:53

3 Comments

Farhan, that is close, but I'm also going to be adding a top border of same width. How do I do that with your solution?
change the 'box-shadow' to 'box-shadow: inset 0px -3px 0px 0px rgba(0,0,0,1), inset 0px 3px 0px 0px rgba(0,0,0,1);'
link just play with box-shadow in before of imgContainer class. check my link to get better idea.
1

The problem with using an inset box-shadow on an image appears to be that the shadow is rendered behind the image.

If you really have your heart set on using a box-shadow, you will need an image with a transparent background... (Convert your jpg to png and delete the background)

.bannerImages {
 -webkit-box-shadow: inset 0px 7px 10px -4px #000 inset, 0px -7px 10px -4px #000 inset;
 -moz-box-shadow: inset 0px 7px 10px -4px #000 inset, 0px -7px 10px -4px #000 inset;
 box-shadow: 0px 7px 10px -4px #000 inset, 0px -7px 10px -4px #000 inset;
}
<img class="bannerImages" src="https://i.sstatic.net/rCgfw.png" />

answered Dec 8, 2014 at 19:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.