Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create border offset?

Tags:

html

css

Hi I was wondering how I can offset a border from a div, like the image: enter image description here

So the gray border is the same size as the image, only it is offset to the right corner. This is my markup:

<figure class="col-md-10 col-md-offset-1">
        <img src="images/image.jpg" alt="Image">
        <figcaption>
            <p>
            Praesent at luctus erat, non finibus justo. 
            <a href="#">share</a>
            </p>
        </figcaption>
</figure><!-- End figure.col-md-10 -->
like image 529
Caspert Avatar asked Aug 11 '26 20:08

Caspert


1 Answers

It's very simple with pseudo elements.

Example

div {
  position: relative;
  margin: 50px 0 0 50px;
  display: inline-block;
}
img {
  display: block;
}
div::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border: 2px solid gray;
  left: 30px;
  top: -30px;
  z-index: -1;
}
<div>
  <img src="http://placehold.it/350x150" alt="">
</div>
like image 75
Narek-T Avatar answered Aug 13 '26 10:08

Narek-T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!