【问题标题】:css grid 100% width and max-widthcss 网格 100% 宽度和最大宽度
【发布时间】:2016-01-20 21:19:00
【问题描述】:

我创建了一个网格,现在遇到最大宽度问题。我想拥有占用可用宽度并受左右边距限制的容器。这个容器可以包含孩子。这些子容器可能比父容器大,并且可以使用 .move-to-right-border 类移动到右边框以占据右侧的全宽。

我现在为容器添加了一个最大宽度,以限制宽度。但是现在我有一个问题,我无法将子元素设置为占据全宽。我尝试使用 100vw,但包含宽度 100vw 的滚动条。有没有人解决这个问题?

也许这个例子会更清楚,注释 max-width in and out 看看我想要什么。

.row-right {
  box-sizing: border-box;
  margin-left: 200px;
  margin-right: 100px;
  max-width: 700px; /* to see the problem comment max-width in and out */
  width: calc(100% - 100px - 200px);
  border: 1px solid red;
}

.move-to-right-border {
  box-sizing: border-box;
  width: calc(100% + 100px);
  border: 2px solid blue;
}

http://codepen.io/anon/pen/eJymOL

【问题讨论】:

  • 你只是想在两边保持均匀的边距?您是否尝试过为您的身体添加填充物? body{ padding-right:200px;} 通过你的笔似乎对我很有效。
  • 我已经建立了一个网格,其中行可以有不同的边距,这就是边距添加到右行的原因。可能还有另一行表现不同。

标签: css grid


【解决方案1】:

只使用下面的css

CSS

.row-right p {
  text-align: justify;
  width : 100%
}

希望对你有帮助:)

【讨论】:

    【解决方案2】:

    我想你喜欢这样的事情:

    .parent{
      position: relative;
      height: 300px;
      padding: 10px 0;
      background-color: #99ff99;
      text-align: center;
    }
    
    .container{
      width: 200px;
      margin: 0 auto;
      height: 100px;
      padding: 30px 0;
      background-color: #ff9999;
    }
    
    .child{
      position: absolute;
      width: 100%;
      height: 50px;
      left: 0;
      background-color: #9999ff;
    }
    <div class="parent">
      This is parent
      <div class="container">
        This is container
        <div class="child">
            This is child
        </div>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2018-09-29
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2014-10-30
      相关资源
      最近更新 更多