The pursuit of equal-height columns in CSS layouts can lead to challenges when relying on percentage-based tables. To address this issue, flexbox offers a robust solution that guarantees equal height for all columns.
The HTML structure remains the same as in the original code:
<ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul>
To implement flexbox for equal height columns, the CSS needs to be modified:
ul { display: flex; }
This simple change transforms the ul into a flex container, and its direct children (li) become flex items. By default, flexbox applies flex-direction: row to align items horizontally.
Align items: stretch
Equal height applies only to siblings
Height overrides
Equal height on same line
Disabling equal height
Flexbox is widely supported by all major browsers except IE versions prior to 10. For consistent support across browsers, consider using Autoprefixer to automatically add vendor prefixes.
The above is the detailed content of How Can Flexbox Achieve Equal-Height Columns in CSS Layouts?. For more information, please follow other related articles on the PHP Chinese website!