Home > Article > Web Front-end > How to Align Inline-Blocks Horizontally on the Same Line?
Inline-blocks offer advantages over floating elements, such as baseline alignment and automatic centering when the viewport becomes narrow. However, aligning two inline-blocks horizontally on the same line can pose a challenge.
One effective solution involves utilizing the text-align: justify technique:
.header { text-align: justify; background: #ccc; } .header:after { content: ''; display: inline-block; width: 100%; height: 0; font-size: 0; line-height: 0; } h1 { display: inline-block; margin-top: 0.321em; } .nav { display: inline-block; vertical-align: baseline; }
The above is the detailed content of How to Align Inline-Blocks Horizontally on the Same Line?. For more information, please follow other related articles on the PHP Chinese website!