下面是我使用的 CSS:
.flip-container
{
-webkit-perspective: 1000;
-moz-perspective: 1000;
perspective: 1000;
}
.flip-container:hover .flipper, .flip-container.hover .flipper {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.flip-container, .front, .back {
width: 150px;
height: 150px;
}
.flipper {
-webkit-transition: 0.6s;
-webkit-transform-style: preserve-3d;
-moz-transition: 0.6s;
-moz-transform-style: preserve-3d;
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
display: table-cell;
vertical-align:middle;
position: absolute;
top: 0;
left: 0;
}
.front {
z-index: 2;
text-align: center;
}
.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.front .name {
font-size: 2em;
display: inline-block;
background: rgba(33, 33, 33, 0.9);
color: #f8f8f8;
font-family: Courier;
padding: 5px 10px;
border-radius: 5px;
bottom: 60px;
left: 25%;
position: absolute;
text-shadow: 0.1em 0.1em 0.05em #333;
-webkit-transform: rotate(-20deg);
-moz-transform: rotate(-20deg);
transform: rotate(-20deg);
}
.back-logo {
position: absolute;
top: 40px;
left: 90px;
width: 160px;
height: 117px;
background: url(logo.png) 0 0 no-repeat;
}
.back-title {
font-weight: bold;
color: #00304a;
position: absolute;
top: 180px;
left: 0;
right: 0;
text-align: center;
text-shadow: 0.1em 0.1em 0.05em #acd7e5;
font-family: Courier;
font-size: 2em;
}
.back p {
position: absolute;
bottom: 40px;
left: 0;
right: 0;
text-align: center;
padding: 0 20px;
}
我使用的 HTML 看起来像这样:
<div id="article"><div class="flip-container" ontouchstart="this.classList.toggle('.'hover'.');">
<div class="flipper">
<div class="front">
<!-- front content -->
</div>
<div class="back">
<!-- back content -->
<img src="" width="160" height="160" /> </div>
</div>
</div>
</div>
文章类的CSS是:
#article {
margin: 5px;
float: left;
height: 150px;
width: 150px;}
我无法使 FRONT div 中心的 fext 垂直居中。它也将是动态的和多行的。有任何想法吗?
我尝试将“vertical-align:middle”与“display:table-cell”一起使用,但这没有帮助,或者我只是将它们应用到了错误的 CSS block 。
代码在 jsFiddle 上:here
最佳答案
您可以对父容器使用 display: table
,对子容器使用 display: table-cell
:
#article {
display:table;
height: 150px;
width: 150px;
float: left;
text-align: center;
}
.front {
display: table-cell;
vertical-align:middle;
}
fiddle 演示: http://jsfiddle.net/uVSN6/1/
关于css - 我如何垂直居中对齐 div 与动态多行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15104250/