Below is the accurate markup for achieving your desired result:
.price-selection {
border: 1px solid #8ABE57;
display: inline-block;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-12 product-info-subtitle cuanto-pagar">
<p>How much do you want to pay?</p>
</div>
<div class="col-12">
<div class="row justify-content-around">
<div class="col-3 price-selection text-center">
<p class="price">one</p>
<p class="period">one</p>
</div>
<div class="col-3 price-selection text-center">
<p class="price">two</p>
<p class="period">two</p>
</div>
<div class="col-3 price-selection text-center">
<p class="price">three</p>
<p class="period">three</p>
</div>
</div>
</div>
</div>
</div>
The key aspect here is that I enclosed the col
elements within a row
with the class of justify-content-around
.
The inclusion of the row
class resolves any margin or padding issues related to Bootstrap grid on different screen sizes.
The use of justify-content-around
provides the functionality equivalent to justify-content: space-evenly
. While Bootstrap currently supports only justify-content-around
and justify-content-between
, flexbox introduced a new value, space-evenly
, which might be incorporated into Bootstrap in the future.
If you wish to evenly space your elements, you can add this CSS class manually:
.price-selection {
border: 1px solid #8ABE57;
display: inline-block;
}
.justify-content-evenly {
display: flex;
justify-content: space-evenly;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-12 product-info-subtitle cuanto-pagar">
<p>How much do you want to pay?</p>
</div>
<div class="col-12">
<div class="row justify-content-evenly">
<div class="col-3 price-selection text-center">
<p class="price">one</p>
<p class="period">one</p>
</div>
<div class="col-3 price-selection text-center">
<p class="price">two</p>
<p class="period">two</p>
</div>
<div class="col-3 price-selection text-center">
<p class="price">three</p>
<p class="period">three</p>
</div>
</div>
</div>
</div>
</div>
To better understand the distinctions between various spacing methods in flexbox, refer to this visual guide: https://css-tricks.com/almanac/properties/j/justify-content/#article-header-id-1