开发者

Middle align three spans in a div (varying heights)

开发者 https://www.devze.com 2023-03-30 15:32 出处:网络
OK given this markup: <div class=\"wrapper\"> <span class=\"left\"></span> <span class=\"middle\"></span>

OK given this markup:

<div class="wrapper">
<span class="left"></span>
<span class="middle"></span>
<span class="right"></span>
</div>

.left and .right are fixed heights, but 开发者_如何学JAVA.middle will be varying height.

So i need it to look like this:

-!!- rather than _!!_ which it is by default.

How can this be achieved?


You can extend the answer you were given yesterday.

Basically, just add vertical-align: middle to the elements with display: inline-block.

See: http://jsfiddle.net/thirtydot/qk4dW/1/ - or here for identical code but with the middle element tallest.

.wrapper {
    text-align: center;
}
.left, .middle, .right {
    vertical-align: middle;

    display:inline-block;
    /* if you need ie6/7 support */
    *display: inline;
    zoom: 1
}
.left, .right {
    height: 100px
}

div {
    border: 1px solid #f0f
}
0

精彩评论

暂无评论...
验证码 换一张
取 消