簡體   English   中英

使div和圖像在div內垂直對齊

[英]make div and image vertically align inside a div

<div class="outside" style="width: 500px; height: 20px; border: 1px solid red;">
    <img src="" style="width: 10px; height: 20px; margin: 0; padding: 0; display: inline-block;">
    <div id="here" style="display: inline-block; height: 15px; border: 1px solid blue; font-size: 7px;">11</div>
</div>

我發現img的底行和#here不在一行,如果我向#here添加任何文本,誰能告訴我原因。 以及如何使#here和img verticall在外部居中(img和#here在同一行中)

您要尋找的是vertical-align

 .outside > * { vertical-align: middle; } 
 <div class="outside" style="width: 500px; height: 20px; border: 1px solid red;"> <img src="http://www.fillmurray.com/20/10" style="width: 10px; height: 20px; margin: 0; padding: 0; display: inline-block;"> <div id="here" style="display: inline-block; height: 15px; border: 1px solid blue; font-size: 7px;">11</div> </div> 

您要在水平中心嗎?

 #ImageCtr { width: 10px; height: 20px; } #outer { width: 500px; height: 20px; background-color: #FF0000; display: flex; align-items: center; justify-content: center; } 
 <div id="outer"> <div id="ImageCtr"><img src="http://i.imgur.com/vCVDBHB.png"> </div> </div> 

對齊內部的圖像和文本<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