CSS:可以做位置:固定偏移中心div吗?
首先,看看我想要实现的布局示例(如下)
基本上,我有一个标准的中心 div(灰色),具有典型的 margin: 0 auto
。我的问题是我有一个背景图像(在白色溢出区域),它是
,具有以下 CSSbackground: url(foo) top center repeat;
position: fixed;
width: 100%;
height: 100%;
此背景应用在 HTML< /code> 文档级别到
#stripes
div。
我遇到的问题是设置下面的红色 div。计划是让它通过 position:fixed
始终保持可见,但是,我不能使用基于 % 的 right: xx%; top: 0
因为图案必须与条纹图案对齐,所以几个像素的偏移会在页面上创建可见且明显的“接缝”。
下面是包含条纹的效果:
First of all, have a look at this example of the layout I'm trying to achieve (below)
Basically, I have a standard center div (gray) with the typical margin: 0 auto
. My problem is that I have a background image (on the white overflow area) that is <div id="stripes">
with the following CSS
background: url(foo) top center repeat;
position: fixed;
width: 100%;
height: 100%;
This background is applied BELOW the HTML
level of the document to the #stripes
div.
What I'm having trouble with is setting up the red div below. The plan is for it to stay visible at all times via position: fixed
however, I can't use % based right: xx%; top: 0
because the pattern must line up with the striped pattern, so a few pixels offset will create a visible and obvious "seam" on the page.
Here is a look at the effect with the stripes included:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终解决这个问题的方法是创建两个 div。在顶层,我使用了标准
width: 960px; margin: 0 auto
div 然后在文档的末尾我创建了另一个具有相同样式的 div 来充当照片的容器(上面的红色 div)。在第二个 div 内部,我嵌套了一个div。该 div 使用以下样式:
父 div 称为
#stripes
The way I ended up solving this was to create two divs. On the top layer, I used a standaard
width: 960px; margin: 0 auto
div and then at the end of the document I created another div with the same styles meant to act as a container for the photo (red div above). Inside of the second div I nested a<div id="photo_bg">
div. This div used the following styles:the parent div was called
#stripes