[英]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.