[英]what is the best way to center image without cropping?
.img_div{
height: 150px;
width: 150px;
overflow: hidden;
}
img.prof_img{
width: 100%;
}
你甚至可以添加一個
轉換:scale(1.1); 如果需要更多居中,請在img.pro_img選擇器內部。
您可以使用類似這樣的東西。
<div class='img_div' style="background-image: url('<?php echo $location; ?>'); background-position: center;"></div>
注意使用background-position: center;
img.prof_img{
height: 100%;
display:block;
margin:0 auto;
}
試試這個插入圖片
.container{ width: 150px; height: 150px; float: left; background: yellow; border: solid 1px #000; text-align: center; } .container img{ max-width: 100%; max-height: 100%; margin: auto; }
<div class="container"> <img src="Untitled-2.png" alt="" title="" /> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.