html / css:在firefox中显示表格单元格不居中文本

时间:2013-07-21 13:14:18

标签: jquery html css firefox

将鼠标悬停在div上的另一个div中,使用不透明度,并将一些文本完美地放在div中。除了firefox之外,这在所有浏览器中都能正常工作 这是一个jsfiddle演示:http://jsfiddle.net/neal_fletcher/WHCNF/

HTML:

<div class="grid-block identity" style="background-image: url('http://placekitten.com/380/250');">
    <div class="grid-block-text-hover-wrap">
    <div class="grid-block-text-wrap">
        <div class="grid-block-text-title">TITLE</div>
        <div class="grid-block-text-subtitle">SUBTITLE</div>
    </div>
    </div>
</div>


CSS:

.grid-block {
    position: absolute;
    width: 380px; height: 250px;
    margin-left: 25px; margin-right: 25px;
    margin-bottom: 50px;
    font-family: 'times';
    text-align: center;
    background: no-repeat 50% 50%;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    cursor: pointer;
    display: table; vertical-align: middle;
}

.grid-block-text-hover-wrap {
    position: absolute; 
    width: 100%; height: 100%; 
    background: rgba(0,0,0,0.75);
    display: table;
    vertical-align: middle;
}

.grid-block-text-hover-wrap .grid-block-text-wrap {
    color: white; 
}

.grid-block .grid-block-text-wrap {
    display: table-cell; vertical-align: middle;
    width: 100%; height: 100%;
}

.grid-block-text-wrap {
    margin-left: 50px; margin-right: 50px;
}

.grid-block-text-title {
    position: relative;
    margin-top: 7px;
    margin-bottom: 20px;
    text-transform: uppercase;
}

.grid-block-text-hover-wrap .grid-block-text-title {
    font-size: 16px;
    line-height: 25px;
    letter-spacing: 2px !important;
}

.grid-block-text-subtitle {
    position: relative;
    font-size: 12px;
    letter-spacing: 2px !important;
    text-transform: uppercase;
}

正如你可以看到.grid-block-text-hover-wrap在悬停时消失,但由于某些原因在firefox中这个div没有正确显示而且没有按照应有的方式居中。我无法弄清楚为什么这似乎正在发生。任何建议将不胜感激!

2 个答案:

答案 0 :(得分:0)

尝试将height: 100%; width: 100%替换为width: 380px; height: 250px。看看新的小提琴:http://jsfiddle.net/WHCNF/1/

答案 1 :(得分:0)

使用

更改当前班级
.grid-block-text-hover-wrap {
position: relative; 
width: 100%; height: 100%; 
background: rgba(0,0,0,0.75);
display: table;
vertical-align: middle; }

我希望它也适用于firefox。