简体   繁体   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>

I found bottom line of img and #here do not in a line, if I add any text to #here, who can tell me why. 我发现img的底行和#here不在一行,如果我向#here添加任何文本,谁能告诉我原因。 And how to make the #here and img verticall center in the outside (img and #here in the same line ) 以及如何使#here和img verticall在外部居中(img和#here在同一行中)

vertical-align is what you are looking for. 您要寻找的是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> 

Do you want it in the horizontal center? 您要在水平中心吗?

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

相关问题 在DIV中水平和垂直对齐图像 - Align image inside DIV horizontally and vertically 将跨度与 div 内的图像垂直对齐 - Vertically align span with image inside div 垂直对齐div内的图像和响应高度 - Vertically align an image inside a div with responsive height 在粘性 div 内垂直对齐图像 - Vertically align image inside a sticky div 如何将文字与图片中的图片垂直对齐<div> - How to align text vertically with an image inside a <div> 在div内水平和垂直居中对齐图像 - Center align image inside div horizontally and vertically 将div中的图像垂直对齐到中间 - Align image inside div to the middle vertically 垂直对齐Div内的图像和文本 - Vertically Align Image and Text Inside a Div 将文本与div中的图像垂直对齐 - Vertically align a text with an image inside a 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM