想要将此菜单栏修复到顶部

时间:2013-09-05 13:25:45

标签: html css menubar

我想在页面顶部修改此菜单栏,以便当用户向下滚动时,菜单栏会继续显示并且内容会流入其中。我尝试通过将位置从相对位置更改为绝对位置来实现,但这没效果。

这是Css

ul.dark_menu {
list-style: none;
padding: 5px 1px;
font-family: 'Segoe UI Light', 'Open Sans', Verdana, Arial, Helvetica, sans-serif;
font-weight: 200;
font-size: 16px;
letter-spacing: 0.01em;
font-smooth: always;
color: #000000;
line-height: 15px;
margin: auto;
width: 1068px;
position: relative;
background: #2B5797;
}/* Blog johanes djogzs.blogspot.com */
ul.dark_menu:after {
content: "";
clear: both;
display: block;
overflow: hidden;
visibility: hidden;
width: 0;
height: 0;}
ul.dark_menu li {
float: left;
position: relative;
margin: 1px;}
/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li a, ul.dark_menu li a:link {
color: #fafafa;
text-decoration: none;
display: block;
padding: 8px 26px;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
-ms-transition: all 0.2s ease;
transition: all 0.2s ease;
}/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li a:hover {
color: #fafafa;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li a.selected {
border-right: 1px solid #ddd;
text-transform: uppercase;
margin-left: 10px;
}
ul.dark_menu li a.selected, ul.dark_menu li a:active {
color: #fafafa;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;}
ul.dark_menu li ul {
display: none;
}/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li ul:before {
content: " ";
position: absolute;
display: block;
z-index: 1500;
left: 0;
top: -10px;
height: 10px;
width: 100%;}
ul.dark_menu li ul {-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;top:55px;}
ul.dark_menu li:hover ul {
position: absolute;
display: block;
z-index: 1000;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
left: 0;border-radius: 0px 0px 5px 5px;
top: 37px;
padding: 5px 0;
list-style: none;
background: #fff;
}/* Blog johanes djogzs.blogspot.com */
ul.dark_menu li ul li {
float: none;
margin:0px;}
ul.dark_menu li ul li:first-child {
margin:0px;
border-top: 0 none;}
ul.dark_menu li ul li:last-child {
border-bottom: 0 none;
}/* Blog johanes djogzs.blogspot.com */
ul.dark_menu [data-role="dropdown"] > a::before {
position: absolute;
content: "^";
display: block;
font-size: 15px;
left: 100%;
margin-left: -20px;
top: 10px;
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-o-transform: rotate(180deg);
transform: rotate(180deg);
}
ul.dark_menu li ul li a, ul.dark_menu li ul li a:link {
color: #222;
display: block;
background: transparent none;
padding: 10px 25px 10px 25px;
white-space: nowrap;}
ul.dark_menu li ul li a:hover {
background:#2D89EF;-moz-transition: all 0.1s ease-in-out;color:#fff;
-webkit-transition: all 0.1s ease-in-out;
}/* Blog johanes djogzs.blogspot.com */
.menujohanes{position:relative;}
#search input[type="text"]:hover {width:848px;}
#search input[type="text"] {
background: #fff url("http://3.bp.blogspot.com/-uYZni0pIn-E/T-xY2vVu_-I/AAAAAAAACUY/ZMfR3_BvRFE/s1600/SEARCH_32x32-32.png")no-repeat center left;
font-size: 13px;
color: #222;
width: 0px;
padding: 10px 0px 11px 35px;
z-index: 9;
border: 1px solid #fff;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
margin-bottom: -1px;
position: absolute;
top: 0px;
right:27px;}

ul.dark_menu li ul li ul li { display: none; }
ul.dark_menu li ul li:hover ul li { display: block;}
ul.dark_menu li ul li:hover ul { left: 100%; top: 0; }

和html

<div class='menujohanes'>
        <ul class='dark_menu'>
          <li>
            <a class='selected' expr:href='data:blog.homepageUrl' title='Home'>
              Home
            </a>
          </li>

       <li data-role='dropdown'>
            <a href='#'>
              Categories
            </a>
            <ul>
                 <li>
                    <a href='#'>
                   Funny Pictures
                    </a>
                        <ul>
                       <li><a href='#'>Funny Gifs</a></li>    

                          <li><a href='#'>Funny Pictures :)</a></li>    
                   </ul>
                </li>
<li>
                <a href='#'>
                  Entertainment
                </a>
<ul>
                       <li><a href='#'>Celebrities Pictures</a></li>    
                </ul> 
              </li>
               <li>
                <a href='#'>
                 Sports
                </a>
                   <ul>
                       <li><a href='#'>Soccer Photos</a></li>    

                       <li><a href='#'>Cricket Stars</a></li>
<li><a href='#'>Famous Tennis Players Pictures</a></li>    
<li><a href='#'>WWE Superstars</a></li>    

                   </ul>
              </li>

            </ul>
          </li>
        </ul>
        <form action='/search' id='search' method='get'>
          <input name='q' placeholder='Search Somethings..' size='40' type='text'/>
        </form>
      </div>

2 个答案:

答案 0 :(得分:1)

更改要保留的div:

position: fixed;
z-index: 100;

z-index用于确保内容在其下流动。该值可以是任何正数,只要它大于您希望在其下流动的任何其他元素。

希望这有帮助!

答案 1 :(得分:0)

在您的情况下,请ul.dark_menu position:fixed;