我想设置图片的背景宽高。
document.getElementById('outerModalPopupDiv').style.backgroundImage = "url('samandar_003.jpeg')";
document.getElementById('outerModalPopupDiv').style.backgroundRepeat = "no-repeat";
现在我想设置图像的宽度和高度。我知道 background-size: 200px 50px;
设置高度和宽度,但我不能使用它们。我必须以上述格式设置宽度和高度。
如果我用
document.getElementById('outerModalPopupDiv').style.background.size = "200px 500px";
那是行不通的。图像保持原样。
知道我怎样才能让它工作。
最佳答案
如图所示 here ,CSS3的background-size
的js语法是:
object.style.backgroundSize="60px 80px"
所以,为了方便复制粘贴,试试这个:
document.getElementById('outerModalPopupDiv').style.backgroundSize = "200px 500px";
关于javascript - 使用css设置背景的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11667469/