The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent.
Syntax:
width: 100%;
Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
<!DOCTYPE html> <html> <head> <title> make a div fill remaining horizontal space </title> <!-- Style to fill remaining horizontal space --> <style> #main { height: 100px; border: 1px solid black; font-size: 20px; font-weight: bold; color: white; } #left { float: left; width: 180px; height: 100%; background-color: green; } #right { width: 100%; height: 100%; background-color: blue; } </style> </head> <body style = "text-align:center;"> <div id = "main"> <div id="left"> DIV_1 </div> <div id="right"> DIV_2 </div> </div> </body> </html> |
Output:

Example 2: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
<!DOCTYPE html> <html> <head> <title> Title </title> <style> #main { height: 100px; border: 1px solid black; font-size: 20px; font-weight: bold; color: white; } #left { float: left; width: 100px; height: 100%; background-color: green; } #center { float: left; width: 100px; height: 100%; background-color: blue; } #right { width: 100%; height: 100%; background-color: green; } </style> </head> <body style = "text-align:center;"> <div id = "main"> <div id="left"> DIV_1 </div> <div id="center"> DIV_2 </div> <div id="right"> DIV_3 </div> </div> </body> </html> |
Output:

Recommended Posts:
- How to overlay one div over another div using CSS
- How to copy the content of a div into another div using jQuery ?
- How to make horizontal line with words in the middle using CSS?
- How to center a div within another div?
- How to clear all div's content inside a parent div ?
- How to make div not larger than its contents using CSS?
- How to make div height expand with its content using CSS ?
- How to make an image center-aligned (vertically & horizontally) inside a bigger div using CSS?
- Make a div horizontally scrollable using CSS
- How to make div width expand with its content using CSS ?
- How to make a HTML div responsive using CSS ?
- How to make a div span two rows in a grid using CSS ?
- How to remove gutter space for a specific div in Bootstrap ?
- How to make horizontal scrollable in a bootstrap row?
- Making a div vertically scrollable using CSS
- How to align content of a div to the bottom using CSS ?
- How to horizontally center a div using CSS?
- How to auto-resize an image to fit a div container using CSS?
- How to give a div tag 100% height of the browser window using CSS
- How to place two div side-by-side of the same height using CSS?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


