I came across a CSS problem, text-align: justify
does not work with only one line.
Justify behavior
The reason is because it has been designed with paragraphs in mind. It justifies all the lines but the last one.
Normal Justify
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat laboris. |
Full Justify
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat laboris. |
Solution
The solution (given by cam) is to put an extra tag at the end of the paragraph that will be big enough to create a new line. Fortunately, it is possible to do it without affecting the markup using :after
. We are going to put an empty tag as big as the line.
.fulljustify { text-align: justify; } .fulljustify:after { content: ""; display: inline-block; width: 100%; } |
Now you can add class="fulljustify"
in order to justify your one-line divs 🙂