简体   繁体   English

用CSS渐变替换背景图片

[英]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. 我需要在响应页面中使用相同的背景样式,但是当元素和图像的大小不匹配时,我找不到解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM