我想将 Div 背景图像设置为适合 div 大小。我从谷歌帮助中尝试了很多。但无法得到解决方案。
我的 div 属性如下
userPic.style.width = "65px";
userPic.style.height = "85px";
userPic.style.position = "absolute";
userPic.style.left = "10px";
userPic.style.top = "10px";
userPic.style.borderRadius = '4em';
现在我正在设置背景图像,如下所示
userPic.style.background = "url('"+employee.profilepic+"') no-repeat";
userPic.className = "profilePic";
我设置了如下的个人资料图片类
.profilePic
{
background-size: 100%;
background-repeat: no-repeat;
overflow: hidden;
margin:auto;
}
但是background-size:100%在chrome中不能正常工作,而且也不能完美工作。我的 div 大小为 65x85,而我的图像大小大于此。那么如何让大图片或小图片适合这个div呢?
最佳答案
我会尝试background-size: cover;
,看看这是否能达到您想要的效果。
关于javascript - 自动调整 Div 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31384836/