Home > Web Front-end > CSS Tutorial > How to Align Inline-Block Columns Vertically?

How to Align Inline-Block Columns Vertically?

Mary-Kate Olsen
Release: 2024-11-05 19:36:02
Original
304 people have browsed it

How to Align Inline-Block Columns Vertically?

Vertical Alignment of Inline-Block Columns

When using display:inline-block to create columns, it becomes apparent that when content is added to the first column, the subsequent columns descend vertically. This can be resolved by utilizing the vertical-align CSS property.

To avoid this issue, add vertical-align: top; to the CSS declaration of the container. This ensures that all columns align vertically at the top, regardless of the content within each column.

.cont span {
    display: inline-block;
    vertical-align: top;
    height:100%;
    line-height: 100%;
    width: 33.33%;
    outline: 1px dashed red; /* Just for Demo */
}
Copy after login

Alternative Approaches

Although inline-block can be used to create columns, it may not be the optimal solution due to potential white space issues between columns. Consider using flex box or CSS grid instead, as they provide more control over column layout and alignment.

The above is the detailed content of How to Align Inline-Block Columns Vertically?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template