无法获得相同高度的柱子和可见的排水沟

时间:2016-12-07 12:49:40

标签: html css grid-layout

我正在尝试创建一个具有相同高度列和可见排水沟的网格。我有相同的高度列,但我不能在与身体元素(米色)相同的背景颜色中制作可见的排水沟。我开始认为我想做的事情不可能用填充物作为排水沟......

我很感谢能得到的所有帮助。 My code

编辑我对自己想要的东西不够清楚。我希望能够改变body-element上的背景颜色,这样它就会影响到gutter。就像你可以使用Bootstrap(我听说它的填充物设置了沟槽)Bootstrap example

请注意,我自己的示例只有一个列大小(.col-6),但我需要能够使用更多不同大小的列,这就是我没有使用边距的原因,因为它很难计算它们的大小,以便所有列大小+边距等于100%宽度。

body {
  background-color: beige;
}

*, *:after, *:before {
  padding: 0;
  margin: 0;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.row {
  overflow: hidden;
}

.col-6 { 
  background-color: black;
  float: left;
  margin-bottom: -99999px;
  padding-bottom: 99999px;
  padding-right: 1.4em;
  width: 50%;
}

[class*='col-']:last-of-type {
  padding-right: 0;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

img {
  display: block;
  max-width: 100%;
}

.information {
  color: white;
}
<div class="row">
  <div class="col-6">
    <img src="https://cdn.pixabay.com/photo/2016/11/08/05/16/ancient-1807518_960_720.jpg" alt="">
  </div>
  <div class="col-6">
    <div class="information">
      <p>Aenean tincidunt ornare lacinia. Suspendisse lacinia bibendum ex, vehicula faucibus mauris ornare at. Fusce nec magna tincidunt urna molestie fringilla.</p>
      <p>Nam fermentum, mauris eget elementum sodales, libero mauris egestas urna, vitae tempor felis felis eget augue.</p>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
body {
  background-color: beige;
}

*, *:after, *:before {
  padding: 0;
  margin: 0;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.row {
  overflow: hidden;
}

.col-6 { 
  background-color: black;
  float: left;
  margin-bottom: -99999px;
  padding-bottom: 99999px;
  padding-right: 1.4em;
  width: 49%;
  margin-right:2%;
}

[class*='col-']:last-of-type {
  margin-right: 0px;
  float:right;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

img {
  display: block;
  max-width: 100%;
}

.information {
  color: white;
}
&#13;
<div class="row">
  <div class="col-6">
    <img src="https://cdn.pixabay.com/photo/2016/11/08/05/16/ancient-1807518_960_720.jpg" alt="">
  </div>
  <div class="col-6 float-right">
    <div class="information">
      <p>Aenean tincidunt ornare lacinia. Suspendisse lacinia bibendum ex, vehicula faucibus mauris ornare at. Fusce nec magna tincidunt urna molestie fringilla.</p>
      <p>Nam fermentum, mauris eget elementum sodales, libero mauris egestas urna, vitae tempor felis felis eget augue.</p>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;