简体   繁体   English

如何在<div>同时保持它在右边?</div><div id="text_translate"><p> 我不知道该怎么做,我试过使用 position,但它只是对齐到页面的中间,而不是 div。</p><p> 我试图在中间垂直对齐它。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> .img1 { float: right; width: 20%; margin-right: 200px; display: inline-block; vertical-align: middle; }.img1 { border-radius: 50%; border: 5px solid white }.container { width: 100%; height: 500px; background-color: black; display: inline-block; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="container"&gt; &lt;img class="img1" src="https://via.placeholder.com/500.jpg"&gt; &lt;/div&gt;</pre></div></div><p></p></div>

[英]how can I vertically align this image within the <div> while keeping it to the right?

I'm not sure what to do, I've tried using position, but it just aligns to the middle of the page, not the div.我不知道该怎么做,我试过使用 position,但它只是对齐到页面的中间,而不是 div。

I'm trying to align it vertically in the middle.我试图在中间垂直对齐它。

 .img1 { float: right; width: 20%; margin-right: 200px; display: inline-block; vertical-align: middle; }.img1 { border-radius: 50%; border: 5px solid white }.container { width: 100%; height: 500px; background-color: black; display: inline-block; }
 <div class="container"> <img class="img1" src="https://via.placeholder.com/500.jpg"> </div>

Wrap it in a flexbox container将其包裹在 flexbox 容器中

 .img1 { float: right; width: 20%; margin-right: 200px; display: inline-block; vertical-align: middle; }.img1 { border-radius: 50%; border: 5px solid white }.container { width: 100%; height: 500px; display:flex; align-items:center; background-color: black; }
 <div class="container"> <img class="img1" src="https://via.placeholder.com/500.jpg"> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使div的子元素垂直浮动的同时保持左右浮动? - How can I vertically-align child elements of a div while keeping them floated to the left and right? 如何在图像的右侧垂直和水平居中对齐文本? - How can I align text centered vertically and horizontally to the right of an image? 如何在div /跨度中垂直对齐图像? - How can I vertically align an Image in a div/span? 如何在div的中间垂直对齐图像和文本 - How can I vertically align an image and text to the middle within divs 如何在图像中水平和垂直对齐文本以保持响应? - How to align texts horizontally and vertically within an image keeping it responsive? css垂直对齐div,同时保持边距 - css vertically align div while keeping margins 如何垂直对齐 div 中的元素? - How can I vertically align elements in a div? 如何在保持文本垂直居中的同时使div的大小与另一个div相同? - How can I make a div grow the same size as another div, while keeping it's text vertically centered? 如何垂直居中 li 导航菜单但将其水平对齐到右侧,同时保持徽标图标水平对齐左和 ctrd vert? - How do I vertically center li navigation menu but horizontally align it to the right while keeping logo icon horizontally aligned left and ctrd vert? 如何在div中垂直对齐图像? - How to Align Vertically the image in a div?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM