Home > Web Front-end > CSS Tutorial > How to Create Equal Height Columns with Pure CSS?

How to Create Equal Height Columns with Pure CSS?

Linda Hamilton
Release: 2024-11-18 11:50:02
Original
961 people have browsed it

How to Create Equal Height Columns with Pure CSS?

Creating Equal Height Columns with CSS

Equal height columns are essential for creating visually appealing layouts. While there are various approaches, one efficient method involves using pure CSS. This tutorial demystifies the technique, dispelling the notion that it's a mere duplication of other solutions.

The Challenge

How can we create columns that:

  • Fill the entire vertical space of their parent div
  • Exhibit equal heights without relying on background images

Based on extensive research, we've discovered a unique solution.

The Answer

For a straightforward approach, embrace the following CSS trickery:

.parent {
  display: table;
}
.child {
  display: table-cell;
}
Copy after login

This trick leverages table-based display properties. When the parent div assumes a table display, its child divs become table cells, inheriting equal height.

Example

<div class="parent">
  <div class="child">Column 1</div>
  <div class="child">Column 2</div>
  <div class="child">Column 3</div>
</div>
Copy after login

Note: IE7 does not play well with this approach, necessitating a more complex solution for backward compatibility.

The above is the detailed content of How to Create Equal Height Columns with Pure CSS?. 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