html - 没有固定大小的容器中的垂直和水平居中文本在 Firefox 中表现得很奇怪

标签 html css layout twitter-bootstrap vertical-alignment

在实现垂直居中时遇到一些麻烦。 似乎在 Chrome 和 Safari 中正常工作,但在 Firefox 中它的行为很奇怪(我在 Mac 上调试)。

当调整浏览器大小时,悬停元素的大小不会调整以适合其父元素,而当浏览器调整为原始宽度时,悬停元素最终会变得太小。

参见 this video
这里是 demo . (Link 到代码 View )

关于如何解决这个问题有什么想法吗?

最佳答案

最终我能够通过这些更改解决这个问题。
希望它能在将来对某人派上用场(链接到答案底部的完整解决方案)。

原始标记

<article class="work-preview">
    <img src="http://lorempixel.com/output/nightlife-q-c-600-414-6.jpg">
    <div class="covering background"></div>
    <div class="covering foreground">
            <h2>A Text</h2>
    </div>
</article> 



新标记

<article class="work-preview">
        <img src="http://lorempixel.com/output/nightlife-q-c-600-414-6.jpg">
        <div class="coveringcontainer">
            <div class="covering foreground">
                <h2>A Text</h2>
            </div>
        </div>
</article> 



原始 CSS

.covering {
    position: absolute;
    top: 0; left: 0;
    opacity: 0;
    filter:alpha(opacity=0);
}

body .work-preview:hover .covering {
    opacity: 1;
    filter:alpha(opacity=100);
    cursor: pointer;
}



新 CSS

.coveringcontainer {
  position: absolute;
  display: none;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: red;
}

.work-preview:hover .coveringcontainer {
  display: block;
  cursor: pointer;
}

.covering {
  position: absolute;
  display: table;
  width: 100%;
  height: 100%;
}



这是 solution完整!

关于html - 没有固定大小的容器中的垂直和水平居中文本在 Firefox 中表现得很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15775614/

相关文章:

html - 在图像上定位输入文本表单和提交按钮

css - 调整页面大小时, float div 会下降

html - Outlook 2003 和字体大小

css - 如何在 Bootstrap 卡片元素之间添加空间?

html - Flex 换行列 : fill the available width with columns

javascript - 仅当div高于一定高度时才在div底部显示 "expand"按钮

数据页面的 HTML 结构语义

javascript - 如何使用id获取 anchor 标签的背景图片url

javascript - 是否建议使用 javascript 构建布局?

html - 将带有和不带有滚动条的容器居中