First of all We need to understand something.
When we use position, we usually need: position:relative for the parent element and position:absolute for the child elements.
If we give to the children position:absolute without using position:relative in the parent, this children will be positioned taking the window as reference, soo they will be positioned in the left/top corner of the window, causing like this a collapse.
Second, when using position:absolute we also need to tell the child where do we want them using top, bottom, left, right you will se in my example.
if we dont use them, they will be positioned in the same spot, causing a collapse.
soo, once expalined this, here is my solution, in my opinion is not the best way to do a dropdown menu.
<div>
<span>Coffee</span>
<span class="sub">Tea</span>
<span class="sub">Milk</span>
<span class="sub">Water</span>
</div>
my HTML is the same as you wanted.
div{
position: relative;
}
span {
display: block;
}
span.sub {
color: blue;
position: absolute;
}
span.sub:nth-child(2){
left: 0;
top: 20px;
display: none;
}
span.sub:nth-child(3){
left: 0;
top: 40px;
display: none;
}
span.sub:nth-child(4){
left: 0;
top: 60px;
display: none;
}
span:first-child:hover ~ span{
display: block;
}
notice that I use left and top as I told before.
First of all we need the parent element, in this case the div to be position: relative because this is our reference.
our span which contains the Coffee word is positioned as it should.
then is quite simple, we need to target each span.sub because they need different values of position not to collapse, I´ve used pseudo-classes to target them, you can also use another class.
and to make a dropdown menu on hover I´ve donee with this line span:first-child:hover ~ span{display: block;} when hover on coffee the display of all span.sub will be changed to block to be able to see them.