2

Though it's a very simple HTML, CSS layout, I am facing problem with this. It does not look like what I want it to be.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <style>
        body {
            margin: 0;
            padding: 100px;
            width: 100%;
        }
        div.container {
            border: 3px red solid;
            padding: 10px;
            display: block;
            width: 1000px;
        }
        div.left, div.right {
            float: left;
            margin: 0 10px;
        }
        div.left {
            background: blue;
            height: 300px;
            width: 300px;

        }
        div.right {
            background: green;
            width: 300px;
            height: 300px;
        }
    </style>
</head>
<body>
    <div class="container">This is the main container
        <div class="left">This is the left side</div>
        <div class="right">This is the right side</div>
    </div>

    I want to know why left and right blocks overlaps the container element?
</body>
</html>

Why left and right blocks overlaps the container element?

I uploaded a screenshot of the code executed in Chrome on PC. Here is the Google Drive preview link: https://drive.google.com/open?id=0B4av_i4gqoZmRFpXbzVZekR0aGs&authuser=0

Thanks in advance.

Arif Billah
  • 157
  • 2
  • 11

1 Answers1

1

Add this style in your CSS file:

.container:before,
.container:after {
    display: table;
    content: " ";
}

.container:after {
    clear: both;
}

This should solve the Issue!

Arqetech
  • 463
  • 1
  • 4
  • 15