I want to position a div beneath its parent in a way that mimics a menu opening below it.
Currently, I attempted using right
and top
, but the child div ends up overlapping the parent.
If the parent had a defined height (rather than top: 0
as shown below), I could have used top
with that height. However, is there a way to achieve this without specifying the parent's height?
.container {
width: 350px;
height: 200px;
}
.parent {
-moz-appearance: textfield;
-webkit-appearance: textfield;
border: 1px solid darkgray;
box-shadow: 1px 1px 1px 0 lightgray inset;
font: -moz-field;
margin-top: 5px;
padding: 2px 3px;
width: 120px;
display: flex;
align-items: center;
position: relative;
direction: rtl;
float:right;
background-color: red;
}
.child {
position: absolute;
background-color: blue;
width: 150px;
height: 200px;
margin: 3px auto;
box-sizing: border-box;
overflow: hidden;
right: 0;
top: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="container">
<div class="parent">
<i class="fa fa-calendar"></i>
<div class="child">
</div>
</div>
</div>