开发者

CSS Position:Absolute with relative adjustment

开发者 https://www.devze.com 2023-01-01 05:46 出处:网络
I am trying to do a vertical dropdown menu. This is my code .menu li:hover>ul{ position:absolute; display:inline;

I am trying to do a vertical dropdown menu. This is my code

.menu li:hover>ul{
position:absolute;
display:inline;
    left:120px;
    top:100px;}

I use position: Absolute to remove the sub-menu from the table, once the 开发者_如何学Gomenu gets hovered. It appears that, if I do not indicate top or left property. The sub-menu will displayed relatively. Now I need to adjust the position relatively but seems that only the left property works. So my sub-menu left position is 120px relatively away from its original position. But the top is 100px away from the top of the window, rather then to the original position. How do I move the list up relative to it original position? I cant use position:relative because I need the sub-menu to be remove from the table.


You need to give it's container a relative position, like this:

.menu li:hover { position: relative; }

This way the positioning of the <ul> inside is absolute, but relative to this container instead of the entire window, which seems to be what you're after.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号