css - 更改背景图像的宽度?

标签 css

我试图改变宽度,但它只改变了 div 的宽度。
我如何使用 css 改变图像的宽度?

#photoTable {
    background-image: url("Assets/Images/FrontImages/partyPhoto.jpg");
    height: 628px;
    vertical-align: top;
    width: 704px;
}

最佳答案

使用 background-size 属性。您可以将其设置为宽度和高度、covercontain。不过,100% 100% 可能最接近您的要求。

#photoTable {
    background-image: url("Assets/Images/FrontImages/partyPhoto.jpg");
    background-size: 100% 100%;
    height: 628px;
    vertical-align: top;
    width: 704px;
}

不适用于 IE 8 或更低版本。

关于css - 更改背景图像的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10692709/

相关文章:

html - 如何让我的 div 外包装,但里面有文字?

css - 每个组件的样式 mat-select-value

css - 无法使用 not(first) 跳过向第一个 li 元素添加 CSS 规则

html - 如何并排显示两个窗体

css - 如何去除图片上的 CSS 链接效果

javascript - 页面运行时更改正文背景图像

jquery - 如何将 "a.hover"转换为单击?

javascript - 使 CSS 工具提示跟随光标

html - 自定义字体渲染问题

html - 声明忽略 parent 填充的背景