How can i create a border outside a div like showed in image

Viewed 60

I am trying to create the border around the section as shown in the image but not sure how can move it few pixels out of the main box. Here is what I tried but its not exactly what I want.

HTML:

<section class="section-steps row outside" id="cities">

<div class="row">
    <h2>Our Values</h2>
</div>
<div class="row js--wp-1 our-values-image-container">
    <div class="col span-1-of-3 box">
        <h3 class="font-weight-bold">Animal Welfare</h3>
        <div class="img-background">
            <img src="resources/img/animal_welfare.jpg" alt="Animal Welfare">
        </div>
    </div>
    <div class="col span-1-of-3 box">
    <h3 class="font-weight-bold">Food Safety</h3>
        <div class="img-background">
            <img src="resources/img/food_safety.jpg" alt="Food Safety">
        </div>
    </div>
    <div class="col span-1-of-3 box">
        <h3 class="font-weight-bold">Sustainability</h3>
        <div class="img-background">
            <img src="resources/img/Sustainability-S.JPG" alt="Sustainability">
        </div>

    </div>

</div>

</section>

CSS:

.img-background{
    background: #ffd203
}
.our-values-image-container{
    padding: 0px 40px;
}

Here is the output:

[![enter image description here][1]][1]

[![enter image description here][2]][2]

2 Answers

Here you should use some CSS properties:

  1. The overflow property that may help you if the text goes out the <div> or the container.

  2. I see that you may want to create a shape as background for your image, so the shape property will help you.

After importing the image, the overflow property turns important here if you want to write on the image.

  1. Now, with position: absolute; make your image stand above the shape. This will help you: Position

I advise you to use classes and ID when using CSS.

Just add box shadow to the image

* {
  margin: 0px;
  padding: 0px;
}

body {
  display: flex;
  justify-content: center;
  height: 100vh;
  align-items: center;
}

img {
  width: 500px;
  box-shadow: -30px -30px 0px yellow;
}
<img src="https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg">

Related