Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

css - Stop page content from moving with drop down menu

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...