Reputation: 6101
I'm solving HTML layout problem similar to drawing responsive Tic Tac Toe board in HTML + CSS and without any JS. Here is how I define the board's layout:
<div class="board">
<div class="lines">
<div class="line">
<div class="cell">
<div class="cell-content"></div>
</div>
<div class="cell">
<div class="cell-content"></div>
</div>
<div class="cell">
<div class="cell-content"></div>
</div>
</div>
<div class="line">
<div class="cell">
<div class="cell-content"></div>
</div>
<div class="cell">
<div class="cell-content"></div>
</div>
<div class="cell">
<div class="cell-content"></div>
</div>
</div>
<div class="line">
<div class="cell">
<div class="cell-content"></div>
</div>
<div class="cell">
<div class="cell-content"></div>
</div>
<div class="cell">
<div class="cell-content"></div>
</div>
</div>
</div>
</div>
and here is the corresponding CSS:
.board {
position: relative;
height: 100%;
width: 100%;
border:1px solid black;
box-sizing:border-box;
}
.board:before {
content:"";
display: block;
padding-top: 100%;
}
.lines {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.line {
width: 100%;
}
.cell {
float: left;
width: 33.3333%;
border:1px solid black;
box-sizing:border-box;
}
.cell:before {
content:"";
display: block;
padding-top: 100%;
}
.cell-content {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
Here I do not set any sizes besides width: 33.3333%
. The height of the board and fields is set using the Height equals width with pure CSS approach.
And I would note that almost everything is great. The only problem here: sometimes the sum of widths/heights of board cells are less than the width/height of the board. It means that I can see the gap between last field border and the board border. I can reproduce it with Chrome or FF, but it never happens in IE. Is there a way to fix this?
The demo is available on the jsfiddle (the red line is what I'm trying to get rid of)
UPDATE: It happens in IE also, not sure why I did not saw it before.
Upvotes: 0
Views: 1653
Reputation: 1682
Simple Fix is to give the .line Elements overflow: auto;
.line {
overflow: auto;
}
and your good to go :D
Upvotes: 1