簡體   English   中英

在DIV容器內水平對齊文本

[英]Horizontally align text inside a DIV container

我有一個像這樣的結構:

    <div class="content-wrapper">
        <div class="left-wrapper">
            Lorem Ipsum... <!-- This is what I want horizontally aligned -->
        </div>
    </div>

我的CSS文件就像:

.content-wrapper {
    min-height: 200px;
    width: 100%;
}

.content-wrapper left-wrapper {
    min-height: inherit;
    width: 50%;
    float: left;
}

我想做的是:不管left-wrapper內的文本有多大,例如,我都希望padding-toppadding-bottom等於30px ,並且我的文本水平完美對齊。

提前致謝!

CSS:

.content-wrapper .left-wrapper {
    min-height: inherit;
    width: 50%;
    float: left;
    text-align:center;
    padding:30px 0;
}

這是一個JSBIN。

.content-wrapper .left-wrapper {
    min-height: inherit;
    width: 50%;
    float: left;
    text-align: center;
}

您可以在這里檢查: http : //jsfiddle.net/0dfxv8tw/

在您的代碼中替換

.content-wrapper left-wrapper {

.content-wrapper .left-wrapper {

並提供

text-align: center;

的HTML

<div class="div01">
<div class="div02">
    <div class="div03">
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    </div>
</div>

的CSS

*{margin:0; padding:0; font-size:12px; color:#333; font-family:Arial;}
.div01 {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
.div02{
height:100%;
width:100%;
display:table;
}
.div03 {
vertical-align:middle;
height:100%;
display:table-cell;
border:1px solid #000;
line-height:22px;
}

小提琴

對齊內部的圖像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直對齊 div 內的圖像和文本。 我的代碼:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起來像這樣: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此處輸入圖像描述"></a></p><p> 我希望“KRON”與圖像對齊。 我做錯了什么?</p></div>

[英]Align image and text inside <div> horizontally and vertically

暫無
暫無

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

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