Den*_*man 3 html css overflow vertical-alignment
我正在制作Img悬停的乐趣.但是现在我的div中有一些文字.我用过代码:
display: table-cell;
vertical-align: middle;
Run Code Online (Sandbox Code Playgroud)
让文本以我的div为中心.我也有这个代码:
.vertical-smallborder{
position: relative;
width: 217px;
height: 350px;
border: 5px solid white;
outline: 1px solid #c8c8c8;
float:left;
display: table;
-webkit-transition: all .3s;
-moz-transition: all .3s;
-ms-transition: all .3s;
-o-transition: all .3s;
transition: all .3s;
overflow: hidden;
}
Run Code Online (Sandbox Code Playgroud)
我display: table在那边找到了文字.如果我删除它,文本将不会在div中居中.
现在我遇到溢出问题:隐藏.在FireFox和IE溢出中:如果存在,则隐藏不再起作用display: table.
谷歌Chrome和Safari都支持display: table和Overflow:hidden一起使用.
注意:它必须是纯CSS.所以我不能使用任何JavaScript.
谢谢
我创建了一个演示如下:
<div class="image-clipper">
<img src="http://placekitten.com/400/500" style="margin: -150px 0 0 -100px;" />
<div class="text-panel">
<div class="text-cell">
<h1>Overhemd<br/>24,95</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
并使用以下CSS:
.image-clipper {
width: 250px;
height: 300px;
border: 5px solid red;
overflow: hidden;
position: relative;
}
.image-clipper .text-panel {
position: absolute;
top: 0;
left: 0;
display: table;
height: 100%;
}
.image-clipper .text-cell {
display: table-cell;
vertical-align: middle;
padding: 20px; /* works okay */
background-color: rgba(255,255,255,0.5); /* applied to entire cell */
}
Run Code Online (Sandbox Code Playgroud)
我能够在父元素中剪切图像,并根据需要定位表/表格单元格.
请参阅演示:http://jsfiddle.net/audetwebdesign/JpMXP/
后记
我没有时间深入审查您的样式表或调查表/表格单元格如何交互的完整细节overflow: hidden.但是,这种方法似乎有效并且相对容易理解.
| 归档时间: |
|
| 查看次数: |
10333 次 |
| 最近记录: |