I'm trying and failing to generate a simple cross (made with vertical
and horizontal
components) within a parent element (box
).
.box {
width: 50vmin;
height: 50vmin;
background-color: blue;
margin: 0 auto;
}
.vertical {
position: absolute;
width: 10%;
height: 80%;
top: calc((100% - 80%) / 2);
left: calc((100% - 10%) / 2);
background-color: black;
}
.horizontal {
position: absolute;
width: 80%;
height: 10%;
top: calc((100% - 10%) / 2);
left: calc((100% - 80%) / 2);
background-color: black;
}
<div class="box">
<div class="vertical"></div>
<div class="horizontal"></div>
</div>
The output that I expected was a black cross centred within the blue a box. Can someone please tell me where I've gone wrong?
Thanks for your help!