Home >Web Front-end >CSS Tutorial >How Can Margins Be Used to Make a Div Fill Remaining Space Between Other Divs?
Using Margins to Fill the Remaining Space
In your HTML, you have set the widths of div1 and div3, but not div2. This leaves an unknown amount of space between the left and right columns, which is where div2 should be.
To make div2 fill the remaining width, you can use margins. Here's how:
#Main { width: 500px; } #div1 { width: 100px; float: left; } #div2 { margin-left: 100px; margin-right: 100px; } #div3 { width: 100px; float: right; }
In this CSS:
With these CSS changes, div2 will automatically fill the remaining width within the #Main container, ensuring that there are no empty gaps between the three columns.
The above is the detailed content of How Can Margins Be Used to Make a Div Fill Remaining Space Between Other Divs?. For more information, please follow other related articles on the PHP Chinese website!