0

I know this has been asked many times but I can't get anything to work. So I'm trying to make this page with 6 "blocks", exctacly 2 rows and 3 columns. It works perfectly with no doctype declaration, and it looks life this. But if I put it in the code this happens.

The CSS code that defines each block properties is the following:

.block {
    position: relative;
    width: 33.33333%;
    height: 50%;
    float: left;
    padding: 0;
    overflow: hidden
}

The head and the body are also set like this:

html, body {height: 100%}

Please tell me there's a solution to this that doesn't involve the use of fixed positions for each block.

domdomcodecode
  • 2,355
  • 4
  • 19
  • 27
Alex
  • 79
  • 1
  • 9

1 Answers1

0

I've just tested this and it works fine. I'm not sure what you have wrong, maybe you've accidentally missed something or have a typo?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html, body {height: 100%}
        .block {
            position: relative;
            width: 33.33333%;
            height: 50%;
            float: left;
            padding: 0;
            overflow: hidden
        }
    </style>
</head>
<body>
<div class="block" style="background-color: aliceblue"></div>
<div class="block" style="background-color: cadetblue"></div>
<div class="block" style="background-color: azure"></div>
<div class="block" style="background-color: aquamarine"></div>
<div class="block" style="background-color: aqua"></div>
<div class="block" style="background-color: antiquewhite"></div>
</body>
</html>
partypete25
  • 4,353
  • 1
  • 17
  • 16
  • I just found out that it was caused by the use of a section tag inside the body tag. I wouldn't have ever imaged it could be caused by that and I really don't understand why this happened. Even thought you didn't post the soluction to this directly, you helped me to notice what the problem was caused by, so really thank you a lot – Alex Dec 03 '15 at 23:54
  • Hi @alex you then need to set the section height to 100% as well! – partypete25 Dec 04 '15 at 00:09
  • I would then think, that because you didn't declare your doctype as html5, section was being ignored. So when you added your doctype, section was recognised but because you didn't set the height to 100% it was then not working the way you wanted. – partypete25 Dec 04 '15 at 00:11