如何垂直对齐这个div

时间:2011-06-13 10:33:43

标签: html css

This是我的实际代码:

<div class="main_right_content">
    <div class="main_right_content_text">
        my text is here and could be as long as possible. for example I write this code some times : my text is here and could be as long as possible. for example I write this code some times : my text is here and could be as long as possible. for example I write this code some times
    </div>

    <a class="main_right_content_link" href="#">Go</a>
</div>

我想,当我最小化窗口时,将链接“go”放在中间关于垂直对齐。事实上,它始终处于最佳状态。

我怎样才能用css(2)做到这一点?

2 个答案:

答案 0 :(得分:3)

您可以在容器position: relative上使用div并在链接上使用position: absolute; right: 0; top: 50%; margin-top: -<height/2>px

请参阅: http://jsfiddle.net/mGJtu/22/

答案 1 :(得分:1)

此解决方案与我完美匹配。即使它是div中的链接或文本,这个CSS类也可以垂直对齐DIV中的内容

 .verticalCenterDivText{
        height: 29px;
        line-height: 29px;
    }