似乎无法弄清楚如何使这些按钮垂直和水平对齐

Code in jsfiddle

的CSS

@font-face {
  font-family: "HemiHead";
  src: url("../../fonts/hemi_head_bd_it.otf");
  src: local("hemi_head_bd_it"),
    url("../../fonts/hemi_head_bd_it.otf") format("opentype"),
  }

/* entire container, keeps perspective */
.flip-container {
    perspective: 1000px;
}
    /* flip the pane when hovered */
    .flip-container:hover .flipper, .flip-container.hover .flipper {
        transform: rotateY(180deg);
    }

.flip-container, .front, .back {
    width: 200px;
    height: 200px;
}

/* flip speed goes here */
.flipper {
    transition: 0.6s;
    transform-style: preserve-3d;

    position: relative;
}

/* hide back of pane during swap */
.front, .back {
    backface-visibility: hidden;

    position: absolute;
    top: 0;
    left: 0;
}

/* front pane, placed above back */
.front {
    z-index: 2;
    /* for firefox 31 */
    transform: rotateY(0deg);
}

/* back, initially hidden pane */
.back {
    transform: rotateY(180deg);
}

.inlineWrapper {
    float: left;
    padding: 5px;
}


html

<div id="background">
    <div class="inlineWrapper">
        <div class="flip-container">
            <div class="flipper">
                <div class="front">
                    <img src="~/Content/Images/SquareTest.png" width="200" height="200" />
                </div>
                <div class="back">
                    <img src="~/Content/Images/SquareTest.png" width="200" height="200" />
                </div>
            </div>
        </div>
     </div>
    <div class="inlineWrapper">
        <div class="flip-container">
            <div class="flipper">
                <div class="front">
                    <img src="~/Content/Images/SquareTest.png" width="200" height="200" />
                </div>
                <div class="back">
                    <img src="~/Content/Images/SquareTest.png" width="200" height="200" />
                </div>
            </div>
        </div>
        </div>
    <div class="inlineWrapper">
        <div class="flip-container">
            <div class="flipper">
                <div class="front">
                    <img src="~/Content/Images/SquareTest.png" width="200" height="200" />
                </div>
                <div class="back">
                    <img src="~/Content/Images/SquareTest.png" width="200" height="200" />
                </div>
            </div>
        </div>
    </div>
 </div>

最佳答案

你需要:


div.inlineWrapper包装为div.container
width: 630pxheight: 210pxtransform: translate(-50%, -50%)left: 50%top: 50%添加到.container
width: 588pxposition: relative添加到#backgruond


这将使您的所有按钮垂直和水平居中。

dabblet上的演示

HTML:

<div id="background">
    <div class="container">
        <div class="inlineWrapper">
            <div class="flip-container">
                <div class="flipper">
                    <div class="front">
                        <img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
                    </div>
                    <div class="back">
                        <img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
                    </div>
                </div>
            </div>
        </div>
        <div class="inlineWrapper">
            <div class="flip-container">
                <div class="flipper">
                    <div class="front">
                        <img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
                    </div>
                    <div class="back">
                        <img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
                    </div>
                </div>
            </div>
        </div>
        <div class="inlineWrapper">
            <div class="flip-container">
                <div class="flipper">
                    <div class="front">
                        <img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
                    </div>
                    <div class="back">
                        <img src="http://dummyimage.com/100x100/000/fff" width="200" height="200" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


CSS:

@font-face {
    font-family:"HemiHead";
    src: url("../../fonts/hemi_head_bd_it.otf");
    src: local("hemi_head_bd_it"), url("../../fonts/hemi_head_bd_it.otf") format("opentype"),
}
/* entire container, keeps perspective */
 .flip-container {
    perspective: 1000px;
}
/* flip the pane when hovered */
 .flip-container:hover .flipper, .flip-container.hover .flipper {
    transform: rotateY(180deg);
}
.flip-container, .front, .back {
    width: 200px;
    height: 200px;
}
/* flip speed goes here */
 .flipper {
    transition: 0.6s;
    transform-style: preserve-3d;
    position: relative;
}
/* hide back of pane during swap */
 .front, .back {
    backface-visibility: hidden;
    position: absolute;
    top: 0;
    left: 0;
}
/* front pane, placed above back */
 .front {
    z-index: 2;
    /* for firefox 31 */
    transform: rotateY(0deg);
}
/* back, initially hidden pane */
 .back {
    transform: rotateY(180deg);
}
.inlineWrapper {
    float: left;
    padding: 5px;
}
.container {
    position: relative;
    width:  630px;
    height: 210px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
#background {
    height: 588px;
    position: relative;
}

关于css - 垂直和水平对齐的CSS问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26983497/

10-13 00:18