简体   繁体   English

集中对齐CSS Box Flip Animation UL

[英]Centrally Align CSS Box Flip Animation UL

I have got a CSS 3D transformation effect, which I would like to align to the center of the page. 我有一个CSS 3D转换效果,我想使其与页面中心对齐。

Basically, I am using two divs; 基本上,我使用两个div; a front and a back in side a div, which then get transformed with CSS by adding a class on hover with jQuery. div的前后两侧,然后通过在jQuery悬停时添加一个类来使用CSS进行转换。

So I would like to align the whole block of boxes (eventually I'll have about five boxes) to the center. 因此, 我想将整个盒子(最终我将有大约五个盒子)对齐到中心。 I have tried: 我努力了:

 ul, #subjectCardsContainer {
   display: block;
   margin-left: auto;
   margin-right: auto;
}

And with 'ul' and '#subjectCardsContainer' on their own 并带有“ ul”和“ #subjectCardsContainer”


My whole code 我的整个代码

JSFiddle 的jsfiddle

 $(document).ready(function() { $(".card").hover(function() { $(this).addClass("flip"); }); $(".card").mouseleave(function() { $(this).removeClass("flip"); }); }); 
 ul, #subjectCardsContainer { display: block; margin-left: auto; margin-right: auto; } li { width: 150px; height: 150px; display: block; position: relative; list-style-type: none; display: inline-block; margin: 0px 5px; } .card { width: 100%; height: 100%; position: absolute; perspective: 800px; } .card div { display: block; position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; -webkit-transition-duration: 400ms; transition-duration: 400ms; z-index: 10; } .card .front { /* Front of each card */ background: red; text-align: center; } .card .back { /* Back of each card */ background: blue; text-align: center; z-index: 0; -webkit-transform: rotateY(180deg); transform: rotateY(180deg); } .card.flip .front { -webkit-transform: rotateY(180deg); transform: rotateY(180deg); z-index: 0; } .card.flip .back { -webkit-transform: rotateY(360deg); transform: rotateY(360deg); z-index: 10; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="subjectCardsContainer"> <ul> <li> <div class="container"> <div class="card"> <div class="front"> <p>Front 1</p> </div> <div class="back"> <p>Back 1</p> </div> </div> </div> </li> <li> <div class="container"> <div class="card"> <div class="front"> <p>Front 2</p> </div> <div class="back"> <p>Back 2</p> </div> </div> </div> </li> </ul> </div> 

use text-align:center for the container. 对容器使用text-align:center

ul, #subjectCardsContainer {
    display: block;
    margin-left: auto;
    margin-right: auto;
    text-align:center;  //added
}

FIDDLE DEMO 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM