【发布时间】:2016-10-06 11:01:00
【问题描述】:
我正在尝试将两个响应式容器连续对齐。其中一个图像内部设置为宽度:100% 和高度:自动。如何在其父响应容器顶部垂直对齐图像?
<div class="top-row">
<figure class="product-image col-sm-6">
<img src="http://rastenis.lt/coocoo/image/cache/catalog/Demo/Untitled.Oil%20on%20canvas.45x55%20cm.2011-570x600.JPG" class="img-r" alt="img">
</figure>
<article class="description col-sm-6">
<h1 class="p-heading">ELEPHANTS ARE COMING BACK</h1>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes </p>
</article>
</div>
CSS
.top-row {
width: 100%;
}
figure img {
width: 100%;
height: auto;
}
【问题讨论】:
-
请在您的问题中输入代码。您在问题中看到了关于在没有代码的情况下链接到 jsFiddle 的大红色警告,但您认为嘿,这不适用于我,所以我将突出显示一些随机单词作为代码来绕过该规则。
-
您肯定知道,您的图像顶部和底部都有空白,对吗?
-
是的,我知道。这就是为什么我要寻求帮助如何正确地做到这一点
-
@TomasRastenis - 我的意思是空白在图像内部。要么裁剪图像以摆脱它,要么使用负边距,或使用负值的绝对位置并隐藏溢出。但最简单的方法就是裁剪图像。
-
谢谢大卫,不知道我是怎么错过的 :)
标签: html css responsive