I have a 4:3
parent, and a child shrinked and centered. Finally a 4:3
child inside.
.table {
position: relative;
width: 400px;
height: 300px;
border: 1px solid;
}
.top {
position: absolute;
left: 15%;
right: 15%;
top: 20%;
bottom: 20%;
background: yellow;
}
.item {
position: absolute;
width: 10%;
height: 50%;
background: pink;
}
<div class="table">
4:3
<div class="top">
<div class="item">4:3</div>
</div>
</div>
.table
has a4:3
aspect ratio.top
is distanced by equal amount from the edges of .table.item
should have a4:3
aspect ratio
In this code .top
is centered and distanced equal from .table
.
Problem is .item
doesn't have 4:3
aspect ratio. (I gave it arbitrary height
, width
). Here's an codepen demo.
Note: .top
is preferred to be distanced equal, it may be close to equal.