Stop page content from moving with drop down menu

放肆的年华 提交于 2020-01-06 14:07:15

问题


Good morning,

I can't stop my content from moving on hover of my dropdown menu. I have tried position:absolute on #sidemenu ul but it doesn't fix it. Here is the html:

<div id="divsidemenu">
    <ul id="sidemenu">
        <li><a href="cv.html">CV</a>
            <ul>
                <li><a href="#cv.html">Map</a>
                </li>
                <li><a href="#">Download</a>
                </li>
            </ul>
        </li>
        <li><a href="#">Portfolio</a>
            <ul>
                <li><a href="#web.html">Web</a>
                </li>
                <li><a href="#print.html">Print</a>
                </li>
                <li><a href="#design.html">Design</a>
                </li>
                <li><a href="#photos.html">Photos</a>
                </li>
            </ul>
        </li>
        <li><a href="#contact" class="anchorLink">Contact</a>
        </li>
    </ul>
    <!--    END OF MENU-->
</div>

and the CSS:

#sidemenu {padding:0; margin:0; list-style:none; text-align: center; width:180px;}

#sidemenu ul {padding:0; margin:0; list-style:none; text-align: center;}

#sidemenu li {background-color:# FFF; margin-bottom:2px; position:relative;}

#sidemenu li li {max-height:0; overflow: hidden; transition: all .5s; border-radius:0; background: `   `#fff; box-shadow: none; border:none; margin:0;}

#sidemenu a {display:block;text-decoration: none;color:#666666; padding: 8px 0; font-family: Verdana, Geneva, sans-serif; font-size:24px}

#sidemenu ul li a, #sidemenu li:hover li a {font-size:18px}

#sidemenu li:hover {background: # CCC;}

#sidemenu li li:hover {background: #999;}

#sidemenu ul li:last-child {border:none;}

#sidemenu li:hover li {max-height: 15em;}

I have tried z-index, position I can't figure it out!

The content is pushed down on hover :(

Thank you so much for any help you can provide, it is greatly appreciated!


回答1:


Try giving position:absolute to #sidemenu ul.

I have made some changes to CSS.

#sidemenu ul {
    background-color: #000000;
    list-style: none outside none;
    margin: 0 0 0 50px;
    padding: 0;
    position: absolute;
    text-align: center;
    z-index: 100;
}

Is this what you are looking for?



来源:https://stackoverflow.com/questions/20740026/stop-page-content-from-moving-with-drop-down-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!