簡體   English   中英

如何垂直對齊這個div

[英]How to vertical align this div

是我的實際代碼:

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

而且我想,當我最小化 window 時,將鏈接“go”放在垂直對齊的中間。 事實上,它始終處於領先地位。

如何使用 css(2) 做到這一點?

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

見: http://jsfiddle.net/mGJtu/22/

這個解決方案非常適合我。 即使它是一個鏈接或只是一個 div 內的文本,這個 CSS Class 可以垂直對齊 DIV 內的內容

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM