Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two borders overlapping with different sizes

Tags:

html

css

Is there any better way of setting two borders like in the example below? I could only do it with positioning. I'm new here so I apologize for any mistakes whatsoever.

.border1 {
  margin: 0 auto;
  height: 300px;
  width: 250px;
  border: 9px solid red;
  position: relative;  
}

.border2 {
  border: 9px solid blue;
  height: 250px;
  width: 300px;
  position: absolute;
  top: 12px;
  left: -33px;
}
<div class="border1">
  <div class="border2"></div>
</div>
like image 852
burcin Avatar asked Jan 28 '26 13:01

burcin


1 Answers

Absolute is indeed a good and easy way here.

You can also use a pseudo and only coordonates to size the second border box.

.border1 {
  margin: 0 auto;
min-height: 150px;/* allow it to grow */
  width: 250px;
  padding:20px 0.5em;
  border: 9px solid red;
  position: relative;
}

.border2:before {
content:'';
  border: 9px solid blue;
pointer-events:none;/* to allow clicking through else you may use a negative z-index */
  position: absolute;
  top: 12px;
bottom:12px;
  left: -33px;
right:-33px;
}
<div class="border1 border2">
add anything here instead setting height
</div>
like image 122
G-Cyrillus Avatar answered Jan 31 '26 04:01

G-Cyrillus



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!