【问题标题】:Bootstrap and body padding left and rightBootstrap 和 body padding 左右
【发布时间】:2014-10-11 11:21:39
【问题描述】:

我正在使用 Bootstrap 创建响应式网页。我需要在 body 中添加 padding-left 和 padding-right 以始终在每一侧都有一个 50px 宽的 >empty safety area

有没有简单的方法来达到这个效果?我只试了下面这个,但看起来不太好(最后容器太窄了)。

// container responsivity fix
.container {
  .container-fixed();

  @media (min-width: @screen-sm-min) {
    width: calc(~'@{container-sm} - 100px');
  }
  @media (min-width: @screen-md-min) {
    width: calc(~'@{container-md} - 80px');
  }
  @media (min-width: @screen-lg-min) {
    width: calc(~'@{container-lg} - 100px');
  }
}

HTML 结构:

<header>
  <div class="container">
    <div class="row">
      <div class="col-xs-12 col-sm-4">
        <a href="#">
          LOGO
        </a>
      </div>
      <div class="col-xs-12 col-sm-5">
        <h2>Lorem ipsum dolor sit amet, <strong> consectetur adipiscing elit.</strong> </h2>
      </div>
      <div class="col-xs-12 col-sm-3 text-right">
        <i class="flag cz active">A</i>
        <i class="flag uk">B</i>
        <i class="flag ge">C</i>
      </div>
    </div>
  </div>
</header>

小提琴:http://jsfiddle.net/o5bkpv7c/

【问题讨论】:

  • 在正文上使用margin
  • 嗯,你试过吗?我以前也有过 - 但它不起作用。
  • 那是因为文字太大了。您可以缩小它的大小或分词。

标签: css twitter-bootstrap responsive-design media-queries padding


【解决方案1】:

文本没有弹性,因此在某个断点之后它不会适合标题。我通常使用中断词或只是缩小文本或使用 fitText.js。有更简洁的方法来做到这一点。

演示:http://jsfiddle.net/o5bkpv7c/4/

body {
    padding: 0 20px;
}
header {
    background: lightblue;
    padding: 1em 0; 
}

header h2 {font-size:1.2rem;margin:10px 0;}


.flag {
    width: 29px;
    height: 20px;
    display: inline-block;
    background: red; 
}

@media (min-width:768px) {
    
    header h2 {font-size:1.3rem;margin:0;}

}

另外,看看你想要的布局,我不会使用网格系统。这是一种更清洁的方法。

http://jsbin.com/tuyeta/1/edit

【讨论】:

  • 嗨,这种行为更清晰,只有当我尝试过时,我的列解决方案在更改视口大小时表现得更好。但无论如何感谢您的解决方案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-17
  • 2018-06-27
  • 2015-12-28
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
  • 1970-01-01
相关资源
最近更新 更多