Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Margin for bottom border

Tags:

html

css

Is there any way I can only add margin to the border ?

Only border should have margin not the text. I am trying to move border not the text field. Border need to be shrinked/moved not text.

CSS :

 .margin-check {
          border-bottom: 1px solid #d2d7da;
          margin-left : 15px;
    }

HTML :

<div class="margin-check">
Something I am typing for checking the border margin
</div>

JS Fiddle: https://jsfiddle.net/c91xhz5e/

like image 505
user2936008 Avatar asked Apr 11 '16 15:04

user2936008


People also ask

What is the margin-bottom?

The margin-bottom CSS property sets the margin area on the bottom of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

What is Border margin?

Border - A border that goes around the padding and content. Margin - Clears an area outside the border. The margin is transparent.

Can we give margin to border?

No, that's not possible. Padding, margin and border are all parts of elements, you can't give a border padding or a margin a border. Maybe if you post an example of what you're trying to do we can come up with alternate solutions?


3 Answers

You can use pseudo-element and then you can change size of border

.margin-check {
  display: inline-block;
  position: relative;
}

.margin-check:after {
  position: absolute;
  content: '';
  border-bottom: 1px solid #d2d7da;
  width: 70%;
  transform: translateX(-50%);
  bottom: -15px;
  left: 50%;
}
<div class="margin-check">
  Something I am typing for checking the border margin
</div>
like image 182
Nenad Vracar Avatar answered Oct 28 '22 15:10

Nenad Vracar


In general the margin is from the content which in this case is your text. You have to use box sizing property to set the margin from you border.

* {box-sizing:border-box;}

This way the margin for all your elements will be from the border box and not the content box

like image 45
Leo The Four Avatar answered Oct 28 '22 17:10

Leo The Four


In your case, where you have no borders left and right, you can simply adjust the line-height.

.margin-check {
   line-height:2em;
}
like image 1
Els den Iep Avatar answered Oct 28 '22 15:10

Els den Iep