Your math for the middle object is exact (100% - 1.5 - 0.3 - 0.3 - 1.5
) = 100% - 3.6em
.
But, apart from the aforamentioned inline-block pitfall, solvable in many ways, eg. using HTML comments to connect the divs, there is another problem.
You are using the (default) W3C Box Model. It excludes borders and padding from the width calculation. So if you have width: 100%, border 10% and padding 10%, your total width is 140%.
Then your padding-left: 0.5em;
is enlarging your middle element of 0.5em.
You can then revisit your math, taking it to 100% - 4.1em;
like in this snippet:
.page-header{
border : 2px dashed lime;
}
.lcars.page-header-before {
width: 1.5em;
height: 2em;
border-radius: 50px 0px 0px 50px;
display: inline-block;
background-color: dodgerBlue;
color: white;
line-height: 1em;
}
.lcars.page-header-after {
width: 1.5em;
height: 2em;
border-radius: 0px 50px 50px 0px;
display: inline-block;
background-color: dodgerBlue;
color: white;
line-height: 1em;
}
.lcars.page-header-middle {
text-transform: uppercase !important;
background-color: orange;
color: blue;
width: calc(100% - 4.1em);
display: inline-block;
height: 2em;
margin-left: 0.3em;
margin-right: 0.3em;
padding-left: 0.5em;
line-height: 1em;
font-size: 1em;
padding-top: 0;
padding-bottom: 0;
}
<div class="lcars page-header">
<div class="lcars page-header-before"> </div><!--
--><div class="lcars page-header-middle">TEST</div><!--
--><div class="lcars page-header-after"> </div>
</div>
Or you can choose to adopt the Traditional Box Model
instead of the W3C Box Model
.
The traditional box model includes borders and padding in the width calculation, as you can see in the following snippet:
* {
box-sizing: border-box;
}
.page-header{
border : 2px dashed lime;
}
.lcars.page-header-before {
width: 1.5em;
height: 2em;
border-radius: 50px 0px 0px 50px;
display: inline-block;
background-color: dodgerBlue;
color: white;
line-height: 1em;
}
.lcars.page-header-after {
width: 1.5em;
height: 2em;
border-radius: 0px 50px 50px 0px;
display: inline-block;
background-color: dodgerBlue;
color: white;
line-height: 1em;
}
.lcars.page-header-middle {
text-transform: uppercase !important;
background-color: orange;
color: blue;
width: calc(100% - 3.6em);
display: inline-block;
height: 2em;
margin-left: 0.3em;
margin-right: 0.3em;
padding-left: 0.5em;
line-height: 1em;
font-size: 1em;
padding-top: 0;
padding-bottom: 0;
}
<div class="lcars page-header">
<div class="lcars page-header-before"> </div><!--
--><div class="lcars page-header-middle">TEST</div><!--
--><div class="lcars page-header-after"> </div>
</div>
Read more about the differences between these two Box Models: