Home >Web Front-end >CSS Tutorial >How to Create a Stable Two-Column Layout in HTML/CSS?
Creating a Stable Two-Column Layout in HTML/CSS
When designing web pages, it's often necessary to create stable, two-column layouts. However, achieving this layout can be challenging, especially when resizing or applying borders. This article explores an approach to create a stable two-column layout in HTML/CSS that addresses the following requirements:
Container Constraints:
Column Constraints (General):
Left Column Constraints:
Right Column Constraints:
Required Stability:
Solution:
To achieve a stable two-column layout, we can leverage the float property. Here's how:
Set the left column to float left:
left { width: 200px; float: left; }
Offset the right column:
#right { margin-left: 200px; }
Clear the float after the columns using a div:
<div class="clear"></div>
This solution allows both columns to coexist without interfering with each other. The left column maintains its fixed width, while the right column fills the remaining space. Any borders or padding applied to the columns will not affect their positioning.
Live Example:
<!DOCTYPE html> <html> <head> <title>Cols</title> <style> #left { width: 200px; float: left; } #right { margin-left: 200px; } .clear { clear: both; } </style> </head> <body> <div>
The above is the detailed content of How to Create a Stable Two-Column Layout in HTML/CSS?. For more information, please follow other related articles on the PHP Chinese website!