我正在尝试使用背景图片(精灵)创建卡片图块。悬停时,我想用一种颜色交换背景图像并添加一些文本。我正在尝试将此文本(可以是1、2甚至3行)放置在图块的正中央。为此,我将基本元素设置为display:table,并将:before
元素设置为display: table-cell
(但仅在悬停时)。
我面临的问题是,将鼠标悬停在基本元素上并移出鼠标后,该基本元素在Mac上的Chrome和Opera中消失了!(在FF和Safari中工作正常。未经IE或Windows / Linux上的任何这些浏览器的测试)。这是我的代码和小提琴:
小提琴:http : //jsfiddle.net/stacigh/0vf47vy5/
.picture {
outline: 1px solid black;
float: left;
margin: 0 10px 10px 0;
width: 150px !important;
height: 150px !important;
background: maroon url('http://www.placehold.it/150x150');
cursor: pointer;
display: table;
}
.picture:hover {
background-image: none;
color: white;
}
.picture:hover:before {
content: 'Test';
text-transform: uppercase;
text-align: center;
display: table-cell;
vertical-align: middle;
}
<div class="picture"></div>
<div class="picture"></div>
<div class="picture"></div>
<div class="picture"></div>
<div class="picture"></div>
<div class="picture"></div>
<div class="picture"></div>
<div class="picture"></div>
编辑:这是行为的GIF
在Chrome Mac中选中时,动态添加表格单元格元素会导致布局中断。
我们可以做的一件事是,我们可以默认添加元素并在悬停时更新其内容。
http://jsfiddle.net/0vf47vy5/5/
.picture:before {
content: '';
text-transform: uppercase;
text-align: center;
display: table-cell;
vertical-align: middle;
}
.picture:hover:before {
content: 'Test';
}
这在Chrome MAC中可以正常使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句