I have a div with some number of spans in it, which may or may not be the same width. I know that I can use text-align: centerto ensure that all content within the div is centered. However, I want to select a specific interval and designate this as the true center, not the center that is the middle of the sequence of intervals.
One of the ideas I had to simulate was the following: I would have the desired middle element with two containers on the left and right; the left would be well-grounded and vice versa. These containers will contain other content in the div. If I could get these two containers to fill the remaining space in equal amounts, this will affect the centering of the middle element while keeping the left and right contents aligned with the center. In principle, this will require that the width of the two containers be set equal to half the remaining space in the div. (I don't want to resize the middle div.) Can this be done only with CSS?
Example: with 4 spans, how do I designate span 2 as a true center?
div {
width: 500px;
padding: 4px;
border: 1px dotted black;
}
span {
display: inline-block;
width: 100px;
text-align: center;
margin: 4px;
box-sizing: border-box;
border: 1px dotted black;
}
#b {
}
<div>
<span id="a">1</span>
<span id="b">2</span>
<span id="c">3</span>
<span id="d">4</span>
</div>
Run codeHide result