html - 无法获得等高的列和可见的装订线

标签 html css grid-layout

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

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

编辑 我对我想要的还不够清楚。我希望能够更改 body-element 上的背景颜色,以便它影响装订线。就像您可以使用 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>

最佳答案

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;
}
<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>

关于html - 无法获得等高的列和可见的装订线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41017946/

相关文章:

html - Css twitter 小部件停留在 firefox 中的元素之外

html - CSS 网格布局中重叠的行

javascript - JQuery 动画速度问题

jquery - 使用按钮隐藏输入类型 "file"

html - 如何在html中堆叠或排序flash对象元素

css - 选中单选按钮时更改文本

html - 绝对定位元素在 Opera、FF 和 Chrome 中看起来相同

css - 具有固定行和列的 polymer 网格

java - 使用日历数据更新网格布局

html - 如何删除 css 中的顶部边距?