Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS, outline-offset: setting the offset for each side individually

Tags:

html

css

outline

In CSS using a outline. Can I set the outline-offset for each side individually?

I don't want to add padding (or any other content) to my element.

Here is a visual representation of what I mean:

enter image description here

Looked all over MDN but couldn't find anything. Is this possible?

like image 503
Willem van der Veen Avatar asked Nov 05 '25 17:11

Willem van der Veen


1 Answers

Use a pseudo element and you can easily control space and size using border:

.outline {
  padding: 10px;
  display: inline-block;
  position:relative;
  margin:20px;
  background:rgba(0,0,0,.2);
}
.outline:before {
  content:"";
  position:absolute;
  left:-10px;
  right:-20px;
  top:-5px;
  bottom:-5px;
  border:2px solid;
  border-right-width:4px;
  border-left-width:5px;
}
<div class="outline">
  Content
</div>
like image 102
Temani Afif Avatar answered Nov 07 '25 09:11

Temani Afif



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!