HTML Layout Using CSS
HTML Layout Using CSS
HTML layout using CSS involves creating the structural content of a webpage and styling it with CSS properties. By using the CSS properties , you can create responsive and attractive webpages.
HTML Layout Using CSS Properties
The following properties of CSS are used to design an HTML layout β
-
CSS float
-
CSS display: flex
-
CSS display: grid
Letβs understand each CSS property with the help of examples and detailed examples. In the below explanation and examples, we will create responsive HTML layouts using these CSS properties.
HTML Layout Using CSS float Property
The float property of CSS allows you to control the positioning of the web page components. When an element is floated, it is taken out of the normal flow of the document and shifted to the specified position, such as left or right .
Example
In the following example, the <nav> and <article> tags have been floated to the left using the float:left property of CSS:
On running the above code, we will get a layout structure consisting of a header, a navigation bar, a content section, and a footer.
HTML Layout Using CSS display:flex Property
The CSS flexbox (also known as Flexible Box Layout) is a more efficient way of designing a layout. It allows developers to arrange and distribute spaces among multiple components of a web page. To use the features of Flexbox, we need to set the display property to flex or inline-flex .
Note: We have a dedicated Flexbox tutorial on our website. Please refer to it for a better understanding.
Example
The following example illustrates how to use the display:flex property of CSS to design a layout of a web page:
On executing the above HTML code, we will get a layout structure.
HTML Layout Using CSS display:grid Property
The CSS grid layout is another addition to the HTML layout designing techniques that define a grid of rows and columns. It also provides abilities to control the sizing as well as the positioning of web page contents.
Example
In this example, we are going to design the same web page layout by using the display:grid property of CSS.
On running the above code, it will generate a layout structure.