Stop page content from moving with drop down menu

2019-09-09 03: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?