I have some span elements inside a col:
<div class="container-fluid">
<div class="row">
<div class="col">
<span class="myClass">some text</span>
<span class="myClass">some text</span>
</div>
<div class="col"></div>
</div>
</div>
myClass elements have some padding:
.myClass{
background: #ecedea;
padding: 10px 10px;
margin-right: 20px;
}
Because there is multiple span elements in the first col, a new line is being created. My problem is because of the padding I have some overlay between my spans in the first line and my spans in the second line:
I tried to add some margin-top to myClass but it didn't help
You can use calculated width/margins., no change to your HTML necessary. E.g. the width of col-md-3 is 100/4=25%. Therefore you can reduce this, say to 20%, and allocate the remaing 5% to your margins. Perfect!
r - sets margin-right or padding-right. x - sets both padding-left and padding-right or margin-left and margin-right. y - sets both padding-top and padding-bottom or margin-top and margin-bottom. blank - sets a margin or padding on all 4 sides of the element.
To add space between columns in Bootstrap use gutter classes. With gutters you can add horizontal or vertical space or even specify how big space should be on different screen size.
You can adjust margins on the column contents using the margin utils such as ml-0 (margin-left:0), mr-0 (margin-right:0), mx-1 (. 25rem left & right margins), etc... Or, you can adjust padding on the columns (col-*) using the padding utils such as pl-0 (padding-left:0), pr-0 (padding-right:0), px-2 (.
span
doesn't have margin because it's an inline
element.
You can fix the CSS like this:
.myClass{
background: #ecedea;
padding: 10px 10px;
display: inline-block;
margin-right: 20px;
}
OR, you can use Bootstrap 4 utility classes and avoid the extra CSS:
<div class="container-fluid">
<div class="row">
<div class="col">
<span class="bg-light d-inline-block p-2 mr-3">some text</span>
<span class="bg-light d-inline-block p-2 mr-3">some text</span>
</div>
</div>
</div>
Demo: https://www.codeply.com/go/jKCFqBb92J
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With