【发布时间】:2017-07-04 12:06:02
【问题描述】:
我需要将我的内容放在 div 中,所以我使用 table-cell 和 vertical-align 来实现它。但是,它只会在 Chrome 中创建一个奇怪的间距,例如 1px。我真的找不到解决办法。请帮帮我。
body {
background: red;
}
.img-wrapper, .txt-wrapper {
height: 300px;
width: 50%;
float: left;
position: relative;
}
.img-wrapper {
background: yellow;
}
.txt-wrapper {
background: green;
display: table;
}
.txt {
display: table-cell;
vertical-align: middle;
}
.col1 {
vertical-align: middle !important;
background: yellow;
width: 50%;
}
.col2 {
background: green;
width: 50%;
}
.pushtoright {
left: 50%;
}
.pulltoleft {
right: 50%;
}
<div class="therow">
<div class="img-wrapper">
<div class="img"></div>
</div>
<div class="txt-wrapper">
<div class="txt">
<h2>Title 1</h2>
<p>Description 1 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
</div>
</div>
</div>
<div class="therow">
<div class="img-wrapper pushtoright">
<div class="img"></div>
</div>
<div class="txt-wrapper pulltoleft">
<div class="txt">
<h2>Title 2</h2>
<p>Description 2 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
</div>
</div>
</div>
<div class="therow">
<div class="img-wrapper">
<div class="img"></div>
</div>
<div class="txt-wrapper">
<div class="txt">
<h2>Title 3</h2>
<p>Description 3 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
</div>
</div>
</div>
<div class="therow">
<div class="img-wrapper pushtoright">
<div class="img"></div>
</div>
<div class="txt-wrapper pulltoleft">
<div class="txt">
<h2>Title 4</h2>
<p>Description 4 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
</div>
</div>
</div>
【问题讨论】:
-
你在哪里看到空间? Mac 上的 Chrome 59.0.3071.115,看不到任何奇怪的空格。
-
我的也是 mac chrome:版本 59.0.3071.115(官方构建)(64 位)。也许可以尝试调整窗口大小?然后会看到红色的 1px 线
-
当您使用 Chrome 开发者工具并转到右侧的“计算”选项卡时,您会看到左侧 div 的宽度为 531px,右侧的 div 为 531.5。太空中似乎损失了半个像素。
-
@Gerard 是的,我也意识到了。但我为每列应用了 50% 的宽度。我该如何解决?看起来很烦人。
标签: jquery html css google-chrome css-tables