我想將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