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

时间:2016-02-06 00:12:49

标签: css menu fixed

我有一个顶部水平菜单栏100%宽度,中心对齐,固定位置,所以它不会与页面滚动。

但我还想在菜单左侧看一个名称(在示例中命名为test),内联菜单。

但即使我使用内联块,它也会根据左侧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/

2 个答案:

答案 0 :(得分:1)

试试这个:

&#13;
&#13;
.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;
}
&#13;
<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.
&#13;
&#13;
&#13;

或在Jsfiddle

中查看此演示

答案 1 :(得分:0)

我重置并更改了一些填充,高度和宽度值。 请尝试以下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;
}

小提琴link