简体   繁体   English

Bootstrap - 容器流体的对齐问题

[英]Bootstrap - alignment issues with container-fluid

I have a comics site, http://hittingtreeswithsticks.com , and want to maintain a 100% width for my header (so it stretches 100% on any browser), but a fixed width for my content (want to maintain fixed 950px width). 我有一个漫画网站, http://hittingtreeswithsticks.com ,并希望我的标题保持100%的宽度(所以它在任何浏览器上延伸100%),但我的内容固定宽度(想要保持固定的950px宽度)。

Therefore, I put the header and footer in <div class="container-fluid"> and the main content in <div class="container"> to achieve that. 因此,我将页眉和页脚放在<div class="container-fluid"><div class="container">的主要内容来实现。

I've been testing locally on IE9, Chrome, and FireFox on a 1920 x 1080 resolution and it the header looked fine. 我一直在IE9,Chrome和FireFox上进行本地测试,分辨率为1920 x 1080,标题看起来很好。

在此输入图像描述

But when I tested on a smaller monitor, 1366 x 768, the header items seems to mush together. 但是,当我在较小的显示器上测试时,1366 x 768,标题项目似乎在一起。

在此输入图像描述

In the header.php file, I have this set up (simplified) for the heading logo and links 在header.php文件中,我为标题徽标和链接设置(简化)

<div class="container-fluid">
   <div id="header">
     <div class="row-fluid">
       <div class="span3 offset3">
         <logo>
       </div>
       <div class="span1">
        <comics link>
       </div>
       <div class="span1">
        <about link>
       </div>
      And so on...

In header.php, I put an opening <div class="container"> so that all other templates that include the header will be within containter and not container-fluid . 在header.php中,我放置了一个开头<div class="container">以便包含标题的所有其他模板都在containter内,而不是container-fluid

Any ideas why that might be happening? 有什么想法可能会发生吗?

Thanks! 谢谢!

You do not have a minimum width set for your content, and thus the browser will "mush" it to make it adapt to smaller resolutions. 您没有为内容设置最小宽度,因此浏览器将“糊涂”它以使其适应较小的分辨率。

You can try to use a CSS rule such as 您可以尝试使用CSS规则,例如

#header { min-width: 1000px; } 

(1000px is arbitrary here). (此处1000px是任意的)。 This will prevent the header from wrapping to two lines, but will obviously cause some part of it to be outside the visiable area in smaller screens. 这将防止标题包裹到两行,但显然会使其中某些部分位于较小屏幕的可见区域之外。

Edit: if you provide a fiddle with your code or a link to a working page, we'd be able to see if there are paddings/margins at play that affect this as well. 编辑:如果您提供代码或工作页面的链接,我们将能够看到是否存在影响这一点的填充/边距。

Try to change the overflow property in your #header element in your comic_style.css 尝试更改comic_style.css中#header元素中的overflow属性

#header {
background: url("images/SiteDesign/Comic_Header.png") repeat scroll 0 0 transparent;
height: 50px;
overflow: auto;scroll;
}

or the img tag in bootstrap.css might be creating problem 或bootstrap.css中的img标记可能会产生问题

img {
    border: 0 none;
    height: auto;
    vertical-align: middle;
}

create another tag for the header image 为标题图像创建另一个标记

Well first of all don't mess anything in the bootstrap.css also it's not so clever to correct something by writing a new css class or something like. 首先,不要在bootstrap.css中弄乱任何东西,通过编写新的css类或类似东西来纠正某些东西也不是那么聪明。

In other words don't try to fix that by css because you will have more problems later. 换句话说,不要尝试通过CSS修复它,因为以后会遇到更多问题。

So here we go 所以我们走了

<div class="container-fluid">

That has to go below not at the top. 这必须低于顶部。

<div id="header">

you don't need that div except if you want a whatever 除非你想要什么,否则你不需要那个div

Be careful with the offset and if try something like that: 小心偏移,如果尝试这样的话:

<div class="container-fluid">
    <div class="row-fluid">
        <div class="span3">

And the most important remember that if you fix something for other size then you have to do it and for other and so on.That means you are not going responsive! 最重要的是要记住,如果你修复了其他尺寸的东西,那么你必须这样做,而其他等等。这意味着你没有响应!

My suggestion is to try with the order of the divs classes and not at all with css. 我的建议是尝试divs类的顺序,而不是css。

I looked at the code on your page, and I believe this may solve your problem: 我查看了您网页上的代码,我相信这可以解决您的问题:

<div id="header">
   <div style="width: 950px;margin-left: auto;margin-right: auto;left: 0;right: 0;">
      <a href="./?action=homepage&amp;page=1&amp;site=comics"> <img id="logo" src="./images/SiteDesign/Logo_Small.png" alt="HTwS Logo"> </a> &nbsp;
      <div class="comicsSite" style="display: inline; background-clip: padding-box; padding-bottom: 15px;">  <a href="./?action=homepage&amp;page=1&amp;site=comics"> <img id="comicssubsite" src="./images/SiteDesign/Comics_subsites.png" alt="Comics"> </a> </div>
      <div class="comicsHeadingOffset" style="display: inline; margin: 0;"> <a href="./?action=about&amp;page=1&amp;site=about"> <img id="aboutsubsite" src="./images/SiteDesign/About_subsites.png" alt="About"> </a> </div>
      <div class="comicsHeadingOffset" style="display: inline; margin: 0;"> <a href="./?action=homepage&amp;page=1&amp;site=artwork"> <img id="artworksubsite" src="./images/SiteDesign/Artwork_subsites.png" alt="Artwork"> </a> </div>
   </div>
</div>

Instead of using spans, you could use the bootstrap nav element: 您可以使用bootstrap nav元素代替使用跨度:

    <div class="navbar>
      <div class="navbar-inner">
        <div class="container-fluid">
          <ul class="nav">
    <li><a href="#">Charts</a></li>
    <li><a href="#">Life</a></li>
    <li><a href="#">Office</a></li>
            <li><a href="#">Political</a></li>
            <li><a href="#">Misc</a></li>
      </ul>
     </div>
       </div>
    </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM