简体   繁体   English

CSS / CSS3背景随内容自动增加

[英]CSS/CSS3 background auto increase with content

how can i make my backgrounds (eg. header bg or footer bg) to auto expand horizontally with the content i put on any of the main content areas in my code? 如何使我的背景(例如页眉bg或页脚bg)自动随我放置在代码中任何主要内容区域的内容水平扩展? .. :) any help is appreciated. .. :)任何帮助表示赞赏。 thanks! 谢谢!

There are a few ways that I can think of: 我可以想到几种方法:

  1. Dynamically create your CSS stylesheet. 动态创建您的CSS样式表。 Doing this will allow you to change the sizes of the image accordingly. 这样做将允许您相应地更改图像的大小。 This is overkill and probably too involved for what you need. 这太过分了,可能太合您需要。
  2. Set the width to be 100% ( width: 100% ). 将宽度设置为100%( width: 100% )。 This will fill the entire area regardless of its size. 无论其大小如何,这将填充整个区域。 This works great in most instances, and might be useful for you. 这在大多数情况下都很好用,可能对您有用。
  3. Create an instance of a repeating background and repeat it horizontally ( repeat-x ). 创建一个重复背景的实例,然后水平repeat-xrepeat-x )。 I think that this is probably the best solution for you as it doesn't distort the background like when stretched as described above. 我认为这可能是最适合您的解决方案,因为它不会像上述拉伸时那样扭曲背景。

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

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