【问题标题】:100% width header fixed with two div's100% 宽度的标题用两个 div 固定
【发布时间】:2014-03-11 14:13:21
【问题描述】:

我正在尝试创建一个固定在滚动顶部的标题。我有一个包装器 (#topbarwrapper) 应该 100% 适合整个浏览器。我在 (#topbarwrapper) 内还有另一个 div 包装器 (.topbarcontentWRAPPER),其中包括徽标和导航 (#mainNav)。一个向左浮动,另一个向右浮动。它们都按应有的方式浮动,但似乎在调整浏览器大小时,div 会移动。我希望浮动在里面的两个 div 以整个页面为中心。布局是响应式的,因此主体宽度为 90%。我花了几天时间试图弄清楚这一点,包括研究。任何帮助将不胜感激。

理想的目标是将 100% 宽度的标题固定并居中。

布局视图: http://s30.postimg.org/so036qarl/Screen_shot_2014_03_10_at_1_53_42_AM.jpg

HTML:

     <body>

        <div id="topbarWRAPPER">
                           <div class="topbarcontentWRAPPER">
              <a href="http://link" title="fvfg" id="topbarLOGO"></a>
              <nav id="mainNav" role="navigation">
                <h2 class="hidden">Main Site Navigation</h2>
                 <?php if ($this->countModules('nav')): ?>
                 <jdoc:include type="modules" name="nav"   />
                 <?php endif; ?> 
              </nav>
           </div>
   </div>     
        <div id="mobilelogo"></div>



          <div id="imageshow">


      </div>


       <div class="wrap">


           <div class="miscellaneousRow">

              </div>


              <div class="search">

              </div>

           </div> 

           <section><h2 class="hidden">Recent News</h2>
           <article id="recentNews">
              <jdoc:include type="component" />
           </article>
           </section>


           <aside>
               <div class="sideBOX">    <section>  
                 <h1 class="sideHeader">MAILING LIST</h1>

                 <div class="signup">

              </section>   </div>


            <div class="sideBOX">   <section>



            </section></div>


         <div class="tabviewTABS">    <section> 


           </section>
               </div>      </aside>

        <footer id="mainbottomFooter">
           <div class="footerFLOATLEFT">
            <h1 class="hidden">Footer</h1>
              <div class="floatone">

              </div>
           </div>

        </footer>
          <div class="secondbottomFooter"> <div class="secondbottomfooterRight">


                  <nav id="sidenav">


                    <ul>

                       <li>

                        <a href="http://www.link.com" target="_blank">l</a>
                       </li>

                       <li>        


                          <a href="http://www.link.com" target="_blank">f</a>
                       </li>

                       <li>

                          <a href="https://link.com" target="_blank">g</a>
                       </li>

                       <li>

                          <a href="http://link.com" target="_blank">x</a>
                       </li>

                       <li>

                          <a href="about.asp">!</a>
                       </li>
                    </ul>
                 </nav>  
              </div>
            <div class="secondbottomfooterLeft"> content</a></div>

           </div>
  </html>

body {
    width:90%;
    margin:0 auto;
    min-width:1024px;
    max-width:1580px;

    }


 .latest-post clearfix{
    display:hidden;}

.imageshow {
    position:relative;
    width: 100%;


}

 .blog-readmore{
    font-size: 24px;
    display: inline;
    width: 180px;
    text-transform:uppercase;
    margin-top:20px;


}



.blog-readmore a:link{
    font-family: arial;

    color: #690000;

    }
.blog-readmore a:visited{
        color: #690000;

}

.blog-readmore a:hover{
        color: #eee;

}



#topbarWRAPPER{
    position:fixed;
    left: 0px;
    right: 0px;
    background-color:#000;
    z-index:1000;
    text-align:center;

}

.topbarcontentWRAPPER {
    display:block;
    height:50px;
    background-color: #1E1E1E;
width: 90%;
    margin: 0 auto;
}





     #topbarLOGO
{

    background-image:url("http://strip2.png");
    background-repeat:no-repeat;
   display:block;      
    float:left;
    height:50px;
    width:250px;
      text-indent:-9999px;
}


aside{
        background-color: #d6d6d6;
    width: 29.1%;
padding-left:1%;

height: 100%;
    float: right;
    overflow: none;
        color: #fff;
                        font-size:10px;
                padding-bottom:1000em;
margin-bottom:-1000em
} 




         /* Blog content */



#recentNews {
    width: 65.1%;
    float: left;
    padding-right:2%;
    padding-left:2%;
    padding-bottom:2%;
background-color:#fff;
padding-bottom:1000em;
margin-bottom:-1000em;
    }


.wrap{ overflow:hidden;
background-color:#fff;
}

/* ~~ Bottom footer ~~ */
#mainbottomFooter{

    background-color:#000;
    position:relative;
    height: 300px;
        clear: both;
        padding:15px 0;
        min-width:100%;

    }


.footerFLOATLEFT li{
     list-style-type: none;
    padding-bottom: 1em;
        padding-top: 1em;
     }




.footerFLOATLEFT a:link{
    font-size:12px;
    color: #555555;
    text-transform:uppercase;}


.footerFLOATLEFT a:visited {
font-size:12px;
    color: #555555;
    text-transform:uppercase;}

    .footerFLOATLEFT a:hover {
font-size:12px;
    color: #690000;
    text-transform:uppercase;}


     /* ~~ P~~ */

p{
            font-size: 17px;
        color: #000; 
        line-height:140%;
    font-family: 'HelveticaNeue';
    padding-left: 1%;
    padding-right:1%;
    font-weight:bold;


     }

h3 {
        margin-bottom: 0px;
font-size: 2em;
color: #690000;
font-family: 'Lato', sans-serif;
font-weight:300;
text-transform:uppercase;
padding-bottom:1em;
padding-top:1em;


}




.floatone {
    float:left;
        padding-right: 4em;
            padding-top: 4em;
            height: 100%;}


.floattwo {

    float:left;
    height: 100%;
        padding: 4em;}


.floatthree {
    float:left;
    height: 100%;
        padding: 4em;}


.floatfour {
    float:left;
    height: 100%;
        padding: 4em;}


.signup {
        width:100%;}





.footerFLOATLEFT {
width:100%;
float:left;

  }


.secondbottomFooter {
    width: 100%;
    height:40px;
background-color:#690000;
border-top:1px solid #222;
border-bottom:1px solid #222;
color: #fff;
font-size: 12px;

padding-top:2em;
padding-bottom:2em;
text-align:right;
  }


h2 {font-face:arial;
    font-size:12px;
    color: #fff;
    padding-top: 1em;
        padding-bottom: 1em;}


#sidenav {


    }


#sidenav li {
display:inline;

}




#sidenav a:link{
    font-family: 'socialicoregular', Arial, sans-serif;
    font-size:5em;
    color: #eee;
    text-decoration:none;

    }
#sidenav a:visited{
        color: #fff;
        text-decoration:none;
}

#sidenav a:hover{
        color: #690000;
        text-decoration:none;
}

.miscellaneousRow {
    background-color: #000;
    width: 100%;
    height:100px;
        position:relative;
}

        .twitterFeed {float:left;
            padding-top: 10px;
                padding-bottom: 10px;
                width: 65.1%;
                                }

            .search {
                float: right;
                padding:2%;
                width: 26%;}






#mainNav {
float:right;
}

.sideDivider {
    background-color:#222;
    height:auto;
    margin-bottom:10%;
    padding-top:10%;
    padding-bottom:5%;
    padding-left:5%;
    padding-right:5%;
    }



.tabviewTABS {
    background-color:#222;
    height:auto;
    margin-bottom:20%;
    padding-top:10%;
    padding-bottom:5%;
    padding-left:5%;
    padding-right:5%;
    }


.sideBOX {
    background-color:#222;
    height:auto;
    margin-bottom:10%;
    padding-top:10%;
    padding-bottom:5%;
    padding-left:5%;
    padding-right:5%;
    text-align:center;
    }



.soundcloud {
    background-color:#222;
position:relative;
    height:auto;
        clear: both;
        padding:15px 0;
        min-width:100%;



    }


.soundcloudtitle {
font-family: 'Droid Serif', serif;
        color: #fff;
        font-size: 2em;
        text-align:right;
        text-transform: uppercase;
                margin-bottom: 1em;
            border-bottom: 5px solid #690000;


    }

.secondbottomfooterRight p{

    padding-right:3em;
    padding-bottom:1em;
    }

.hidden 
    {
  position: absolute !important;
  clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);

}

【问题讨论】:

    标签: html css responsive-design


    【解决方案1】:

    您将 topbarWRAPPER 的左右位置设置为 0px 而不是 5%。

    this fiddle

    编辑: 我明白你的意思了。我已经更新了the fiddle。它应该是你需要的。

    编辑#2: 好的。原谅我,我之前没有注意到这一点。您已经为主体指定了百分比宽度,但指定了最小和最大宽度(以像素为单位)。如果您删除最小和最大宽度,您将看到您正在寻找的行为,但我认为您应该做的是将 70% 宽度分配给 .wrap 并给它一个 @987654329 @

    【讨论】:

    • 您好,感谢您的回复。我左右为 0px 的原因是将 topbarWRAPPER 扩展到主网页主体之外并 100% 跨过屏幕,以便整个 div 贴在页面顶部。我可能解释错了,但为了更好地说明我正在尝试做的事情,这里是一个模板的链接,它完全按照我的意愿去做。 link
    • 我真的很感激你在帮助我。它仍然无法正常工作。 TOPBARCONTENTWRAPPER 中的内容仍然超出了居中的页面内容。我创建了一个{链接](jsfiddle.net/CQLnS)。您还可以看到内容如何不断扩展。它为徽标和导航执行此操作。 [链接] (postimg.org/image/undweouq9)。
    • 谢谢你的工作!换行只是使用 padding-bottom:1000em 使两个列具有相同的高度;边距底部:-1000em 并放置溢出:无;在 .wrap
    • 很抱歉再次打扰您,但我有最后一个问题,解决了扩展问题,您有什么建议不要让徽标和导航重叠吗?似乎当浏览器变小时,导航会位于徽标下方。我希望他们两个都留在原地。这是一个小提琴 [链接] (jsfiddle.net/CQLnS/1)
    • 这是 min-width 派上用场的地方。您需要将min-width:500px 放在body 和topbarcontentWRAPPER 上。在这种情况下为 500 像素,因为这是导航和徽标组合的总宽度。
    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 2013-11-25
    • 1970-01-01
    相关资源
    最近更新 更多