【发布时间】:2013-11-19 03:06:52
【问题描述】:
这是我建立的第一个综合网站,如果我遗漏了任何明显的内容,我深表歉意。
我正在尝试将高度和宽度可变的图像垂直和水平居中放在一个高度可变的容器中。这样客户端可以替换图像或更改最终控制高度的相邻 div 中的内容。
我正在使用绝对居中,在 this article 以及它引用的其他内容中进行了描述。
它在 Chrome 和 Safari 中运行良好,但 Firefox 不显示图像。在无休止的修补和寻找问题之后,我举手了。我知道垂直居中还有其他解决方案,但这似乎是唯一可以处理所涉及的大多数元素的可变性的解决方案。
非常感谢任何建议的 css/html 更改以使其工作。发生这种情况的实际站点是here。
<div class="partner_section">
<div class="partner_details">
<div class="span_2 float-right">
<h4>Heading</h4>
<p>content</p>
<h4>Heading</h4>
<p>Content</p>
<div class="partner_cta">
<a href="/canvas-shoes/black/">CTA</a>
</div>
</div>
<div class="span_2 float-left pImageContainer">
<a href="http://springboardcollaborative.org/"><img class="" alt="SpringBoard Logo" src="/templates/__custom/images/custom/sblogo.png"></a>
</div>
</div>
</div>
</div>
.partner_section {
width: 100%;
overflow: hidden;
position: relative;
padding: 40px 0 40px 0;
z-index: 100;
}
.partner_details {
overflow: auto;
width: 980px;
margin: auto;
position: relative;
height: 100%;
display: table;
}
.pImageContainer {
height: 100%;
overflow: auto;
text-align: center;
position: relative;
}
.pImageContainer img {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
margin: auto;
}
.span_2 {
width: 49%;
}
.float-right {
float: right;
}
.float-left {
float: left;
}
【问题讨论】: