I know that an element with position: absolute
is moved out of the normal flow and positioned to its nearest positioned ancestor, or to the initial containing box.
But in the code below the div
of class: face bottom
is positioned at the top-left corner of its container box cube
, which shouldn't be since neither of its ancestors---the cube
and the container
---has a position
attribute set.
To which positioned element is it absolutely positioned to? Or if it is positioned to the initial containing box (which I think is not the case), what is this initial containing box?
<body>
<table>
<tbody>
<tr>
<td>
<div class="container">
<div class="cube">
<div class="face bottom">6</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</body>
* {
box-sizing: border-box;
}
/* Define the container div, the cube div, and a generic face */
.container {
width: 200px;
height: 200px;
margin: 75px 0 0 75px;
border: 3px solid black;
}
.cube {
width: 100%;
height: 100%;
border:3px dashed red;
backface-visibility: visible;
perspective-origin: 150% 150%;
transform-style: preserve-3d;
}
.face {
display: block;
position: absolute;
width: 100px;
height: 100px;
border: none;
line-height: 100px;
font-family: sans-serif;
font-size: 60px;
color: white;
text-align: center;
}
.bottom {
background: rgba(196, 0, 196, 0.7);
}
th,
p,
td {
background-color: #eeeeee;
padding: 10px;
font-family: sans-serif;
text-align: left;
}
BTW, this code comes from an MDN page that demonstrates the building of 3D cubes. I deleted code unrelated to this problem for simplicity.