css从定义的位置开始重复背景
#container{
background:url(images/bg-main.png) repeat-y;
width: 903px;
background-position: 0px 687px;
background-position: bottom;
height: 1200px;
margin-left: auto;
margin-right: auto;
}
#content{
background:url(images/bg-wood.png) repeat-y;
width: 903px;
height: 678px;
margin-left: auto;
margin-right: auto;
}
#content
div 位于 #container
div 内。我希望 #container
的背景从顶部开始重复 687 像素。是否可以?
编辑:是否有可能 div 的前 x 像素(从顶部)有空空间,并且在 x 像素背景开始之后?
#container{
background:url(images/bg-main.png) repeat-y;
width: 903px;
background-position: 0px 687px;
background-position: bottom;
height: 1200px;
margin-left: auto;
margin-right: auto;
}
#content{
background:url(images/bg-wood.png) repeat-y;
width: 903px;
height: 678px;
margin-left: auto;
margin-right: auto;
}
#content
div is inside #container
div. I want #container
's background to start repeating at 687px from top. Is it possible?
EDIT: Is it possible that first x pixels of div (from top) have emtpy space and after x pixels backgrund starts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
重复 x 和重复 y 不可能在沿轴的两个方向上重复图像,
据我所知,如果您重复容器背景全长,则 内容 div 背景图像是否未覆盖无论如何,先增加 678px 吗?
您能否在 JSFiddle 中提供代码,以便我们可以看到您想要实现的效果,会有一种方法;)
As far as I know it's not possible how you're trying to do it, repeat-x and repeat-y, will repeat the image in both directions along the axis
if you repeat container background full length does the content div background image not cover up the first 678px anyway?
can you provide code in a JSFiddle so we can see what effect you're trying to achieve there will be a way ;)
您可以使用伪元素(
::before
或::after
)来实现此目的,并利用calc()
来获取偏移量。伪元素将为您提供更多控制,不会影响内容,并且不需要额外的 HTML 标记。
这是一个距离顶部 100px 偏移的基本示例:
您还可以使用相同的技术从左侧偏移:
或者甚至从两个方向(也相反!):
You can achieve this with pseudo element (
::before
or::after
) and take advantage ofcalc()
for the offset.Pseudo element will give you more control and won't affect the content and does not require the need for an extra HTML tag.
Here is a basic example with 100px offset from top:
You can also use the same techique to offset from left:
Or even from both directions (reversed, too!):
这将从顶部 287 像素处垂直重复您的背景图像。
但另一种方法是将其设置为您的内容 div :
最好的解决方案是这样做:
This will repeat vertically your background image from 287px from top.
but another way is to set this to your content div :
you best solution is to do like this :