Forum Moderators: not2easy
-----------------
| 1 | 2 | 3 | 4 |
-----------------
| 5 |///////| 6 |
----|///X///|----
| 7 |///////| 8 |
-----------------
| 9 | 10| 11| 12|
-----------------
[edited by: asterickx at 2:37 pm (utc) on Dec 3, 2014]
-----------------
| 1 | 2 | 3 | 4 |
-----------------
| 5 | space | 6 |
----|-------|----
| 7 | space | 8 |
-----------------
| 9 | 10| 11| 12|
-----------------
<div class="container">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li class="spacer"> </li>
<li>6</li>
<li>7</li>
<li class="spacer"> </li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
</ul>
<div class="X">X</div>
</div>
.container {
/* Relatively positioned so X will be positioned from top left of container */
position: relative;
}
ul,
li {
/* Remove all list styling. Set margin and padding to 0 avoid complex calculations */
list-style: none;
margin: 0;
padding: 0;
}
ul {
/* Fixed width divisible by 4 to get 4 equal columns */
width: 400px;
}
li {
/* box-sizing to include borders in width calculations, avoids complexity */
box-sizing: border-box;
/* Fixed width = 1/4 of ul width */
width: 100px;
/* Fixed height for each box. Should be 1/2 of X height. */
height: 100px;
/* Float each box */
float: left;
/* Center aligned text makes sample easier to view */
text-align: center;
/* Border to show edges of box */
border: 1px solid black;
}
li.spacer {
/* Fixed width = 1/2 of ul width */
width: 200px;
}
.X {
position: absolute;
/* Fixed left = li width (or 1/4 of ul width) */
left: 100px;
/* Fixed top = li height */
top: 100px;
/* Fixed width = li width x 2 (or 1/2 ul width) */
width: 200px;
/* Fixed height = li height x 2 */
height: 200px;
/* Background required to cover spacers underneath */
background: #ccc;
}
.X {
position: absolute;
/* Fixed left = li width (or 1/4 of ul width) */
left: 101px;
/* Fixed top = li height */
top: 101px;
/* Fixed width = li width x 2 (or 1/2 ul width) */
width: 198px;
/* Fixed height = li height x 2 */
height: 198px;
/* Background required to cover spacers underneath */
background: #ccc;
}
Also, an alternative to using spacer items might be to apply a left margin to items 6 and 8.
But you'd need to do some tweaking to get the borders right.
Just set the <ul> element's CSS 'position' to something like "position:relative; top:0; left:0;" to give the enclosed <li> elements a known point of reference.
But just for the sake of it: could it be done with floats only?
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li><ul><li>5</li><li>7</li></ul></li>
<li class="X">X</li>
<li><ul><li>6</li><li>8</li></ul></li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
</ul>
ul,
li {
/* Remove all list styling. Set margin and padding to 0 avoid complex calculations */
list-style: none;
margin: 0;
padding: 0;
}
ul {
/* Fixed width divisible by 4 to get 4 equal columns */
width: 400px;
}
ul ul {
/* Nested ul is width of a single column */
width: 100px;
}
li {
/* box-sizing to include borders in width calculations, avoids complexity */
box-sizing: border-box;
/* Fixed width = 1/4 of ul width */
width: 100px;
/* Fixed height for each box. Should be 1/2 of X height. */
height: 100px;
/* Float each box */
float: left;
/* Center aligned text makes sample easier to view */
text-align: center;
/* Border to show edges of box */
border: 1px solid black;
}
li:nth-child(5),
li:nth-child(7) {
/* Fixed height = li height x 2 */
height: 200px;
}
li.X {
/* Fixed width = li width x 2 (or 1/2 ul width) */
width: 200px;
/* Fixed height = li height x 2 */
height: 200px;
/* Background required to cover spacers underneath */
background: #ccc;
}