I have a div (the parent) which when hovered on, a menu will appear.
The parent is 30px X 30px.
The menu is a position absolute element which can expand upto 200px based on the content.
The problem with this is, the child doesn't expand beyond the 30px of the parent. But what I want is for it to expand to it's content and stop expanding after 200px.
Is there a different way to do this without setting a fixed width to the child?
.parent {
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
background-color: yellow;
border: 1px solid;
position: relative;
}
.child {
position: absolute;
background-color: aqua;
border: 1px solid;
display: none;
max-width: 200px;
}
.parent:hover .child {
display: block;
}
<div class="parent">
P
<div class="child">
Hey diddle diddle the cat and the fiddle.
</div>
</div>
Hover over the parent to see the child element is taking the parent's size.