html - Twitter 喜欢固定标题

标签 html css menu header

如何在页面顶部创建固定的标题,如 Twitter/Facebook?

我正在对此进行测试,但是当我调整浏览器大小时,整个设计都变形了

  <div id="head">
   <div id="logo">
    <a href="#"></a>
   </div>
   <div style="display:inline;">
    <input style="margin-top:3px;" class="searchbox" type="text"/>
   </div>
 <ul>
  <li>
   <a href="#" title="Home">Home</a> 
  <li>
  <li>
   <a href="#" title="Profile">Profile</a> 
  </li>
  <li>
   <a href="#" title="Profile">Actions</a> 
  </li>
  <li>
   <a href="#" title="Profile">Invite Friends</a> 
  </li>
 </ul>


</div>
<div id="content">
      </div>

风格

     html {
         height:100%; /* fix height to 100% for IE */
         max-height:100%; /* fix height for other browsers */
         padding:0; /*remove padding */
         margin:0; /* remove margins */

         background:#fff; /*color background - only works in IE */
         /* hide overflow:hidden from IE5/Mac */
         /* \*/
         overflow:hidden; /*get rid of scroll bars in IE */
         /* */
}
body {
         height:100%;
         max-height:100%;
         min-width:960px;
         overflow:hidden;
         padding:0;
         margin:0;
         font: 13px/1.5 Helvetica Neue,Arial,Helvetica,'Liberation Sans',FreeSans,sans-serif;
}
#content {
         display:block;
         height:100%;
         max-height:100%;
         overflow:auto;
         position:relative;
         z-index:3;
         word-wrap:break-word;
         top:45px;
}
#head {
         position:absolute;
         margin:0;
         top:0;
         display:block;
         width:100%;
         height:40px;
            -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
         background:#333333;
            background: -moz-linear-gradient(center top , #736F6E, #111111) repeat scroll 0 0 transparent;

}
#logo a {
            background: url("2.gif") no-repeat scroll 6px 2px transparent;
            color: #FFFFFF;
            display: block;
            height: 100%;
            margin-right: 5px;
            outline: medium none;
            text-indent: -9999px;
            width: 140px;
           float:left;
}
.searchbox{
            -moz-border-radius: 4px 4px 4px 4px;
            -moz-box-shadow: 0 1px 0 #444444;
            background: none repeat scroll 0 0 #666666;
            border: 1px solid black;
            color: #CCCCCC;
            font: 13px Arial,sans-serif;
            padding: 6px 5px 4px 26px;
            width: 215px;
         float:right;
}

.searchbox:focus {
            background: none repeat scroll 0 0 #eeeeee;
            border: 1px solid #999999;
        }
#head ul {
          margin:0;
          padding:0;
          background:transparent;
          height:100%;
          margin-left:60px;
          padding-left:660px;
          padding-top:10px;
}
#head ul li {  display:inline;}
#head ul li a { padding-left:10px;  color:#BABABA; text-decoration:none;}
#head ul li a:hover { color:#FFFFFF;  }

编辑 样本 http://jsfiddle.net/zerotoinfinite2006/tTmSH/embedded/result/

最佳答案

您的#head 元素需要有固定的定位才能使其 float 在顶部。这将使它始终保持在顶部。试试这个

#head {
     position:fixed;
     margin:0px;
     top:0px;
     left:0px;
     display:block;
     width:100%;
     height:40px;
     -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
     background:#333333;
     background: -moz-linear-gradient(center top , #736F6E, #111111) repeat scroll 0 0 transparent;
}

关于html - Twitter 喜欢固定标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8303273/

相关文章:

android - 为什么父Activity的菜单在TabHost中不显示?

html - 长表列表的样式问题

javascript - 为什么我网站的 slider 只能在 Mac(同一浏览器)上正常工作?

html - 删除 HTML CSS 中的下划线格式

java - 如何确定哪个菜单项称为 ActionListener?

调整 IE 大小时 HTML 列表项换行

html - CSS Position - 如何制作动画框?

javascript - 使用 JavaScript 切换 HTML5 全屏 API

html - 使用 css 隐藏 div 内容不起作用

html - 文本需要跨越 2 行,无法使用列表、div 或表格来完成