水平菜单,位置固定,在 div 旁边

horizontal menu, position fixed, next to div

我有一个顶部水平菜单栏,宽度为 100%,居中对齐,位置固定,因此它不会随页面滚动。

但我还想在菜单的左侧、菜单的内联中添加一个名称(例如名为 test)。

但是即使我使用了inline-block,它还是按照左边div.

    <div class="name">test</div >

<div id="menu"> 
        <ul>
                <li><a href="index.php?menu=1" border="0" alt="menu1">menu1</a></li>
                <li><a href="index.php?menu=1" border="0" alt="menu1">menu2</a></li>
                <li><a href="index.php?menu=1" border="0" alt="menu1">menu3</a></li>
                <li><a href="index.php?menu=1" border="0" alt="menu1">menu4</a></li>
                <li><a href="index.php?menu=1" border="0" alt="menu1">menu5</a></li>

        </ul>
</div>

和CSS

.name {
font-size: 12pt;
font-weight: bold;
height: 20px;
color: #ffffff ;
Width: 99%;
display:  ;
position:fixed;
z-index:2;
padding: 5px;
top: 2px;
}


#menu {
 background: #bbbbbb;
 top: 0px;
 height: 35px;
 width: 99.8% ;
 text-align: center ;
 position:fixed;
 z-index:1;
 }


}

#menu ul{
display: ;
height: auto;
padding: 8px 0px;
margin: 0px;
z-index:3;
}

#menu li {
display: inline;
z-index:3;
}



#menu a {
display: inline-block;
font-weight: bold;
font-size: 15px;
color: red;  
text-decoration: none;
vertical-align: bottom;  
padding: 20px; 

}

参见示例:https://jsfiddle.net/sm6npxdc/3/

试试这个:

.name {
  font-size: 12pt;
  font-weight: bold;
  height: 20px;
  color: #ffffff;
  Width: 99%;
  display: inline-block;
  position: fixed;
  z-index: 2;
  padding: 5px;
  top: 2px;
}
#menu {
  background: #bbbbbb;
  top: 0px;
  height: 35px;
  width: 99.8%;
  text-align: center;
  position: fixed;
  z-index: 1;
}
#menu ul {
  line-height: 2.000;
  padding: 0px;
  margin: 0px;
  z-index: 3;
  margin: 0px;
}
#menu ul li {
  display: inline-block;
  z-index: 3;
  padding: 0px 12px;
}
#menu a {
  font-weight: bold;
  font-size: 15px;
  color: red;
  text-decoration: none;
}
<div class="name">test</div>

<div id="menu">
  <ul>
    <li><a href="index.php?menu=1" border="0" alt="menu1">menu1</a>
    </li>
    <li><a href="index.php?menu=1" border="0" alt="menu1">menu2</a>
    </li>
    <li><a href="index.php?menu=1" border="0" alt="menu1">menu3</a>
    </li>
    <li><a href="index.php?menu=1" border="0" alt="menu1">menu4</a>
    </li>
    <li><a href="index.php?menu=1" border="0" alt="menu1">menu5</a>
    </li>

  </ul>
</div>

<div style='clear:both; margin-top:40px;'>
</div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta.
Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam.
In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla
metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor
neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Quo usque tandem abutere, Catilina, patientia nostra? Quam diu etiam
furor iste tuus nos eludet? Quem ad finem sese effrenata iactabit audacia? CICERO Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis
sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum
sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer
lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi
lectus, commodo ac, facilisis ac, ultricies eu, pede.

或在 Jsfiddle

中查看此演示

我重置并更改了一些填充、高度和宽度值。 请尝试以下 css:

*{
  margin: 0;  
  padding: 0;
}
.name {
font-size: 12pt;
font-weight: bold;
height: 20px;
color: #ffffff ;
display:  ;
position:fixed;
z-index:2;
padding: 5px;
top: 2px;
}
#menu {
 background: #bbbbbb;
 top: 0px;
 width: 99.8% ;
 text-align: center ;
 position:fixed;
 z-index:1;
}
#menu ul{
display: ;
height: auto;
margin: 0px;
z-index:3;
}
#menu li {
display: inline;
z-index:3;
}
#menu a {
display: inline-block;
font-weight: bold;
font-size: 15px;
color: red;  
text-decoration: none;
vertical-align: bottom;  
padding: 10px;
}

fiddle link