Inner border over images with CSS?

前端 未结 5 1822
滥情空心
滥情空心 2020-12-02 16:47

I would like to add a white border over all my images in my content div using css. Images in the header and footer div areas should not be affected. how do I achieve this?

5条回答
  •  渐次进展
    2020-12-02 17:49

    You can do this without having an extra element or pseudo element:

    http://cssdeck.com/labs/t6nd0h9p

    img {
      outline: 1px solid white;
      outline-offset: -4px;
    }
    

    IE9&10 do not support the outline-offset property, but otherwise support is good: http://caniuse.com/#search=outline

    Alternate solution that doesn't require knowing the dimensions of the image:

    http://cssdeck.com/labs/aajakwnl

    div.ie-container { display: inline-block; position: relative; } div.ie-container:before { display: block; content: ''; position: absolute; top: 4px; right: 4px; bottom: 4px; left: 4px; border: 1px solid white; } img { vertical-align: middle; /* optional */ }

提交回复
热议问题