Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css border-bottom before padding

Tags:

html

css

Is it possible to apply a border-bottom before padding without inserting an immediate element, i.e., within the content box itself? For example, below I created a wrapper div with s3 on the class. Can I avoid this?

Here is a JSFiddle.

.top {
  border: 1px solid black;
}
.s2 {
  margin: 15px;
  padding: 15px;
  border-bottom: 1px solid blue;
}
.s3 {
  border-bottom: 1px solid blue;
}
<div class="top">
  <div class="s2">
    s2
  </div>

  <div class="s2">
    <div class="s3">
      wrapped in s3
    </div>
  </div>
</div>

I've been searching around for a solution to this which leads me to think it's not possible. I don't mind using any solution as long as it does not require me positioning items relatively or absolutely. Thought CSS pseudo-element might allow me to do this but it doesn't.

like image 682
Mohamed Bana Avatar asked Nov 29 '22 10:11

Mohamed Bana


1 Answers

You certainly can do this with a pseudo element.

.item {
    margin: 15px;
    padding: 15px;
    background: #f2f2f2;
}

.item:after {
    content: "";
    display: block;
    border-bottom: 1px solid blue;
}
<div class="item">
  Hello!
</div>

Updated Fiddle

like image 91
Turnip Avatar answered Dec 11 '22 00:12

Turnip