Sirac Sirac - 13 days ago 5
CSS Question

Tiling the page with CSS

I want to tile my page horitontally and vertically, recursively too. E.g. that the page is split into three columns, whereby the third column is split into two rows.

<div id="left/>
<div id="right">
<div id="top">...</div>
<div id="bottom">...</div>
</div>


This fiddle explains what I am talking about:
https://jsfiddle.net/zuyu1ed7/

This design works, until you start adding content. Giving one of these containers a border, a margin or a padding results in chaos. The whole layout seems to be very sensible.

Also, trying to add an
<div style="width:100%; padding: 10px;"/>
inside these containers has the same layout-destructing effects. This situation trandcends my knowledge about css.

At first I thought of using tables, your best friend if css keeps mocking you. But then I saw that html5 does not longer support most
colgroup
-attributes. So that idea was an dead end.

My question is: How do I split div's horizontally and vertically as shown in the fiddle and be able to add content to the containers?

I am thankful for any solution, but of course I would prefer a solution that works in all browsers.

Answer

Have you considered flexbox? It is basically supported by all modern browsers.

Fiddle

html, body {
  width: 100%;
  height: 100%;
}

* {
  margin: 0px;
  padding: 0px;
}

body {
  display: flex;
}

#left {
  height: 100%;
  width: 20%;
  background-color: Blue;
}

#right {
  height: 100%;
  width: 80%;
  background-color: Green;
  display: flex;
  flex-direction: column;
}

#top {
  width: 100%;
  height: 33.33%;
  background-color: lightblue;
}

#center {
  width: 100%;
  height: 33.33%;
  background-color: lightgreen;
}

#bottom {
  width: 100%;
  height: 33.34%;
  background-color: black;
  display: flex;
}

#bottom-left {
  height: 100%;
  width: 35%;
  background-color: Yellow;
}

#bottom-right {
  height: 100%;
  width: 65%;
  background-color: orange;
}
<div id="left">
  </div>
  <div id="right">
      <div id="top"></div>
      <div id="center"></div>
      <div id="bottom">
          <div id="bottom-left"></div>
          <div id="bottom-right"></div>
      </div>
  </div>

Comments