简体   繁体   中英

Div center the screen instead of on the top when linked from navigation bar

When I try to use the same page linking in HTML, it brings the DIV on the top of the page. I would like to center it on screen.

The navigation bar:

<div id="nav">
    <ul id="navlist">
        <li id="navitem"><a href="index.html#someitem">Div1</a></li>
        <li id="navitem"><a href="index.html#someitem">Div2</a></li>               
     </ul>
</div>

#navlist
{
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 1;
    display:none;
}

Div:

<div id="someitem"> </div>

#someitem
{
  padding: 15px;
  height: 400px;
  width: 100%;    
}

Is this something you were looking for?

 #navlist { list-style-type: none; margin: 0; padding: 0; overflow: hidden; position: fixed; width: 100%; left: 0; right: 0; z-index: 1; text-align: center; } ul li { display: inline-block; } 
 <div id="nav"> <ul id="navlist"> <li id="navitem"><a href="index.html#someitem">Div1</a></li> <li id="navitem"><a href="index.html#someitem">Div2</a></li> </ul> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM