How to Vertically Align Inline-Block Columns for Consistent Layout?

Barbara Streisand
Release: 2024-11-05 21:13:02
Original
729 people have browsed it

How to Vertically Align Inline-Block Columns for Consistent Layout?

Vertical Alignment of Inline-Block Columns

When using inline-block to create columns, it's crucial to address the challenge of columns shifting down with added content in the first column. To resolve this issue, we need to ensure proper vertical alignment.

The solution lies in adding CSS declarations to vertically align the columns at the top:

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

This ensures that even with varying content in the first column, the other columns remain aligned at the top.

While inline-block does have its drawbacks, it's still an effective option for creating simple columns. However, consider using flexbox or CSS grid for more advanced column layouts.

The above is the detailed content of How to Vertically Align Inline-Block Columns for Consistent Layout?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!