How to Create a Two-Column Layout with a Fixed-Width Right Column?
How to Create a Two-Column Layout with a Fixed-Width Right Column
In web design, it's often necessary to create a layout with two columns, one of which has a fixed width while the other is fluid. Despite being a common requirement, finding a solution that works consistently can be challenging.
In this specific case, the goal is to create two columns where the right column maintains a constant width while the left column expands or contracts based on the available space. Here's a step-by-step answer:
- Remove Float from Left Column: Removing the float property on the left column allows it to flow naturally.
- Move Right Column Before Left Column: In the HTML, the right column should come before the left one.
- Set Width and Float on Right Column: Define a fixed width for the right column and apply a float to it (e.g., float: right).
- Add Overflow and Height to Outer Div: Apply an overflow: hidden and a height (can be auto) to the outer div containing both inner columns.
- Add Auto Width and Overflow to Left Column: Set the width of the left column to auto and apply overflow: hidden. This ensures its independence from the right column.
Example HTML:
<div class="container"> <div class="right"> Right Content (Fixed Width) </div> <div class="left"> Left Content (Flexible Width) </div> </div>
CSS:
.container { height: auto; overflow: hidden; } .right { width: 180px; float: right; background: #aafed6; } .left { float: none; background: #e8f6fe; width: auto; overflow: hidden; }
This solution creates the desired two-column layout with a fixed-width right column while allowing the left column to adjust dynamically based on the browser window size.
The above is the detailed content of How to Create a Two-Column Layout with a Fixed-Width Right Column?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

One thing that caught my eye on the list of features for Lea Verou's conic-gradient() polyfill was the last item:

Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

The inline-template directive allows us to build rich Vue components as a progressive enhancement over existing WordPress markup.

PHP templating often gets a bad rap for facilitating subpar code — but that doesn't have to be the case. Let’s look at how PHP projects can enforce a basic

Every time I start a new project, I organize the code I’m looking at into three types, or categories if you like. And I think these types can be applied to
