我想将div背景图像设置为适合div尺寸。我正在尝试从谷歌帮助很多。但无法获得解决方案。Autofit 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;
}
但背景大小profilepic类:100%在铬合金中工作不正常,而且工作不完美。我有尺寸为65x85的div,我的图像尺寸大于此值。那么如何在这个div中适合大或小的图像呢?
您是否尝试在背景大小中使用'cover'或'contain'属性值? –
我试过了,但是它在调试窗口中显示罢工。这意味着它不起作用。 – VarunJi