简体   繁体   English

覆盖引导容器宽度

[英]override bootstrap container width

I have an easy HTML template using bootstrap 3. Template has following structure: static header, static footer and content which is in the bootstrap's class "Container". 我有一个使用bootstrap 3的简单HTML模板。模板具有以下结构:静态页眉,静态页脚和引导程序类“容器”中的内容。 In the middle of content I have bootstrap'w "Well" and i want it make looks like header and footer. 在内容的中间我有bootstrap'w“嗯”,我希望它看起来像页眉和页脚。 I mean I want it to be the full width of the screen on any screen. 我的意思是我希望它在任何屏幕上都是屏幕的整个宽度。

I created easy fiddle. 我创造了轻松的小提琴。

Here's a question, is there any way to override container's width inside this container? 这是一个问题,有没有办法在这个容器内覆盖容器的宽度?

<header>
   <div class="container">
      <div class="content">

      </div>
      <div class="well">

      </div>
      <div class="content">

      </div>
   </div>
<footer>

在此输入图像描述

The div container has the following max-width specified in media query as default by bootstrap. div container在媒体查询中指定了以下max-width ,默认为bootstrap。

@media (min-width: 768px){
  .container{
    max-width:750px;
  }  
}

@media (min-width: 992px){
  .container{
    max-width:970px;
  }
}

To override this add the below style in your stylesheet 要覆盖它,请在样式表中添加以下样式

// This should be added in default styles, not within media query .container{ margin:0; //这应该在默认样式中添加,而不是在媒体查询中添加.container {margin:0; padding:0; 填充:0; } }

@media (min-width: 768px){
  .container{
    max-width:100%;
  }  
}

@media (min-width: 992px){
  .container{
    max-width:100%;
  }
}

ORIGINAL + BEST PRACTICE: always move the .well outside of .container to stay idiomatic with Bootstrap ORIGINAL +最佳实践:始终将.well移动到.container之外,以便使用Bootstrap保持惯用

UPDATE + IF ABOVE IS NOT AN OPTION: Given that you cannot easily modify .container styles and/or move the .well outside of .container , your best bet is JavaScript. UPDATE + IF上面没有一个选项:既然你不能轻易修改.container风格和/或移动.well之外.container ,最好的办法是JavaScript的。 Here I have made a script that makes .well expand as the width of the window changes. 在这里,我制作了一个脚本,当窗口的宽度发生变化时,.well会扩展。

http://jsfiddle.net/iamnotsam/E3RQp/1/ http://jsfiddle.net/iamnotsam/E3RQp/1/

The idea is that you want a negative value for margin-left and margin-right so that .well expands across the screen. 这个想法是你需要一个负值margin-left margin-right以便.well在屏幕上扩展。

Here theres a simpler trick that works like a charm: https://css-tricks.com/full-width-containers-limited-width-parents/ 这里有一个更简单的技巧,就像一个魅力: https//css-tricks.com/full-width-containers-limited-width-parents/

Look for: "No calc() needed" 寻找:“不需要calc()”

HTML HTML

<header>
    <div class="container">
        <div class="content"></div>
        <div class="well full-width"></div>
        <div class="content"></div>
    </div>
    <footer>

CSS CSS

.full-width {
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

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

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