【发布时间】:2016-03-30 09:37:28
【问题描述】:
我需要在多个元素上制作一个连续的背景图案。
我无法控制元素的高度或数量。
这是一个例子:
p{
margin:0;
padding:1.5em;
}
.bg{
background-image:url('http://enjoycss.com/webshots/hB_1.png');
}
<p>some text<br>on several lines</p>
<p class="bg">some text<br>on several lines</p>
<p class="bg">some text<br>on several lines<br><br>and another<br>some text<br>on several lines<br><br>and another</p>
<p class="bg">some text<br>on several lines<br><br>and another</p>
<p>some text<br>on several lines<br><br>and another<br>some text<br>on several lines<br><br>and another</p>
<p class="bg">some text<br>on several lines</p>
<p class="bg">some text<br>on several lines<br><br>and another<br>some text<br>on several lines<br><br>and another</p>
<p class="bg">some text<br>on several lines<br><br>and another</p>
我要的效果用background-attachement:fixed;几乎可以实现,但是我需要背景随着内容滚动。
示例:
p{
margin:0;
padding:1.5em;
}
.bg{
background-image:url('http://enjoycss.com/webshots/hB_1.png');
background-attachment:fixed;
}
<p>some text<br>on several lines</p>
<p class="bg">some text<br>on several lines</p>
<p class="bg">some text<br>on several lines<br><br>and another<br>some text<br>on several lines<br><br>and another</p>
<p class="bg">some text<br>on several lines<br><br>and another</p>
<p>some text<br>on several lines<br><br>and another<br>some text<br>on several lines<br><br>and another</p>
<p class="bg">some text<br>on several lines</p>
<p class="bg">some text<br>on several lines<br><br>and another<br>some text<br>on several lines<br><br>and another</p>
<p class="bg">some text<br>on several lines<br><br>and another</p>
【问题讨论】:
-
你不能把它们包装在
div中并为其分配背景吗? -
@NicklasNygren 不,内容是由所见即所得的编辑器生成的,客户端无法制作容器,他只能更改
p元素的类。
标签: javascript jquery css background background-image