Block layout. Part 2

In the last topic, the creation of a page with two columns was considered. Similarly, we can add more columns to the page and make the structure more complex. For example, let’s add a second sidebar to the web page:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Block Layout in HTML5</title>
    <style>
        div {
            margin: 10px;
            border: 1px solid black;
            font-size: 20px;
            height: 80px;
        }

        #header {
            background-color: #ccc;
        }

        #leftSidebar {
            background-color: #ddd;
        }

        #rightSidebar {
            background-color: #bbb;
        }

        #main {
            background-color: #eee;
            height: 200px;
        }

        #footer {
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <div id="header">Header</div>
    <div id="leftSidebar">Left Sidebar</div>
    <div id="rightSidebar">Right Sidebar</div>
    <div id="main">Content area</div>
    <div id="footer">Footer</div>
</body>

</html>


Here again, the code for both sidebars should go before the main content block that wraps around them.

Now let’s change the styles of both sidebars and the main block:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Block Layout in HTML5</title>
    <style>
        div {
            margin: 10px;
            border: 1px solid black;
            font-size: 20px;
            height: 80px;
        }

        #header {
            background-color: #ccc;
        }

        #leftSidebar {
            background-color: #ddd;
            float: left;
            width: 150px;
        }

        #rightSidebar {
            background-color: #bbb;
            float: right;
            width: 150px;
        }

        #main {
            background-color: #eee;
            height: 200px;
            margin-left: 170px;
            margin-right: 170px;
        }

        #footer {
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <div id="header">Header</div>
    <div id="leftSidebar">Left Sidebar</div>
    <div id="rightSidebar">Right Sidebar</div>
    <div id="main">Content area</div>
    <div id="footer">Footer</div>
</body>

</html>

Again, for both floating blocks – sidebars, we need to set the width and property float- one has a value left, and the other has a value right.