CSS问题对齐垂直和水平

时间:2014-11-17 22:53:10

标签: css css3

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

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>

1 个答案:

答案 0 :(得分:1)

你需要:

  1. div.inlineWrapper换成div.container
  2. width: 630pxheight: 210pxtransform: translate(-50%, -50%)left: 50%top: 50%添加到.container
  3. width: 588pxposition: relative添加到#backgruond
  4. 这将使所有按钮垂直和水平居中。

    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;
    }