[英]css table-cell and vertical align middle not working in firefox
I am trying to vertically center the contents of .onesizechart, which I have working in bothChrome and Safari, but does not work in either Firefox or IE. 我试图垂直居中.onesizechart的内容,我已经在Chrome和Safari中工作,但在Firefox或IE中都不起作用。 The contents of .homepage-sizechart are displaying fine which makes me think I am missing something very simple.
.homepage-sizechart的内容显示正常,这让我觉得我错过了很简单的东西。 Any ideas?
有任何想法吗?
HTML/Liquid HTML /液体
<div class="medium-3 small-6 columns homepage-products left" onclick="location.href='{{ product.url }}'">
<div class="product-preview-image-div">
<a href="{{ product.url | within: collection }}">
<img src="{{ product.featured_image | product_img_url: 'grande' }}" alt="{{ product.title | escape }}" />
</a>
{% assign contains_os = false %}
{% for variant in product.variants %}
{% if variant.title contains 'OS' %}
{% assign contains_os = true %}
{% endif %}
{% endfor %}
{% if contains_os %}
<div class="onesizechart">
{% for variant in product.variants %}
{% if variant.inventory_quantity == 0 %}
<img src="{{ 'onesize-triangle-outofstock.png' | asset_url }}"/>
{% else %}
<img src="{{ 'onesize-triangle.png' | asset_url }}"/>
{% endif %}
{% endfor %}
</div>
{% else %}
<div class="homepage-sizechart">
<div class="sizes">
{{ 'size-triangle.png' | asset_url | img_tag }}
{% for variant in product.variants %}
<span class="{{ variant.title }}-product {% if variant.inventory_quantity == 0 %}outofstock{% endif %} {% if variant.title contains 'OS'%}hide{% endif %}">{{ variant.title }}</span>
{% endfor %}
</div>
</div>
{% endif %}
</div>
</div>
CSS CSS
.homepage-products {
cursor: pointer;
margin-top: 20px;
}
.homepage-sizechart {
bottom: 0;
display: table-cell;
left: 0;
margin: auto;
opacity: 0;
position: absolute;
right: 0;
text-align: center;
top: 5%;
vertical-align: middle;
width: 90%;
z-index: 999;
}
.onesizechart {
opacity: 0;
position: absolute;
display: table;
width: 90%;
z-index: 999;
top: 5%;
bottom: 0;
right: 0;
margin: auto;
text-align: center;
}
.onesize {
display: table-cell;
vertical-align: middle;
}
.sizes {
position: relative;
}
You need to set your parent container to display:table;
您需要将父容器设置为
display:table;
for the child elements using display:table-cell
to inherit tabular like properties such as vertical-align
. 对于使用
display:table-cell
的子元素display:table-cell
继承表格式属性,例如vertical-align
。
HTML: HTML:
<div class="container">
<div class="panel">
hey
</div>
<div class="panel">
hey
</div>
</div>
CSS: CSS:
.container {
display:table;
height:100px;
}
.panel {
display:table-cell;
vertical-align:middle;
border:1px solid red;
}
Although you haven't provided the CSS for the .product-preview-image-div
class above, I'm guessing that this is most likely the problem at play. 虽然你没有为上面的
.product-preview-image-div
类提供CSS,但我猜这很可能是游戏中的问题。
JSFiddle: http://jsfiddle.net/a4fyg/ JSFiddle: http : //jsfiddle.net/a4fyg/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.