[英]Center image in div, with same proportions and overflow hidden, and always fill
Sounds like you may want to put the image as a background inside of a div as a container and then put the text or whatever inside another div?... maybe like this? 听起来您可能想将图像作为背景放在div作为容器的内部,然后将文本或其他内容放入另一个div?...也许是这样?
.container{
background:url('image.png') no-repeat;
width:500px;
height:500px;
overflow:hidden;
}
.content{
width:20%;
height:10%;
margin: 0 auto;
}
<div class="container">
<div class="content">
text here text here text here text here
</div>
</div>
I believe you may possibly be looking for background-size: cover;
我相信您可能正在寻找background-size: cover;
in combination with background-position: center
. 结合background-position: center
。
This means your div
would have CSS defined like the following; 这意味着您的div
将具有如下定义的CSS;
div {
background: url('image.png');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width:100px;
height:100px;
overflow:hidden;
}
Hope that helps you out! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.