When forcing a line of text or inline-elements to be justified within its parent by adding an ::after
rule, I noticed that the parent will expand in height, to fit the pseudo-element, even if I try to prevent it:
.test {
background-color:#ccc;
text-align:justify;
}
.test:after {
display:inline-block;
content:'';
width:100%;
height:0;
}
<div class="test">test 1 foo bar</div>
Here's what I tried so far and what it got me (in order of increasing despair):
height:0
on the pseudo-element: no changeline-height:0
on the pseudo-element: no changeoverflow:hidden
on the pseudo-element: no change- a combination of 2 or all of the above: no change
- negative margin or padding on the pseudo-element: no change (negative padding is invalid as far as I know, but at that point I began to become desperate)
white-space:nowrap
on the pseudo-element: no changewhite-space:nowrap
on the parent: broke the layoutposition:relative;top:-100%
on the pseudo-element: no changeposition:absolute
on the pseudo-element: broke the layout
Any suggestions other than giving the parent a fixed height or using flexbox?