[英]Replace background image with CSS gradient
I use an image for the background of a fixed-width div with id header
, the relevant CSS rule is 我将图像用作ID header
的固定宽度div的背景,相关的CSS规则是
#header {
background: url("bg.png") no-repeat scroll center top rgba(0, 0, 0, 0);
}
I'm trying to make this page more responsive, which means that the width of header
is now variable. 我正在尝试使此页面更具响应性,这意味着header
的宽度现在是可变的。 In the unresponsive page the header
element was always the same width as the background image, but in the responsive design the element could be wider or narrower than the image. 在无响应页面中, header
元素的宽度始终与背景图像相同,但在响应式设计中,该元素可以比图像宽或窄。 I need to use the same background style in the responsive page, but I can't find a way to do this when the size of the element and image don't match. 我需要在响应页面中使用相同的背景样式,但是当元素和图像的大小不匹配时,我找不到解决方法。
You could consider 你可以考虑
background: url("bg.png") repeat-y top left;
background-size: cover;
W3schools has more info on the background-size property W3schools具有有关background-size属性的更多信息
EDIT: Since that W3Schools seems a form of heresy, here is another reference 编辑: 由于W3Schools似乎是一种异端形式,因此这里是另一种参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.