布局问题,部分固定宽度,部分弹性
我已经浏览了一些帖子,但找不到我想要的东西。我目前正在 PS 中设计一些东西,我可以预见到将设计编码为 html+css 时会出现问题。
想象一下我的中心 div,它是 960px
。它将有一个半透明的 .png
作为背景。设计是“全宽”,因此该 div 将包含在一个更大的 div 中,宽度设置为 100%。这一切都很好,直到我到达这个外部 div 的背景。它还将有一个 .png 占据页面的整个宽度。问题是:我不希望它穿过中间,因为这会导致中间有双倍的厚度,如果这有意义的话?!
基本上,我需要一种方法来在有弹性的两侧运行 div,或者以某种方式阻止背景在浏览器窗口的中心 960px
部分运行。
除了使用 JS 设置宽度(我真的不想这样做)之外,我不知道如何实现这一点。
有什么想法吗?
好的,我尝试在这里解决基本问题: http://jsfiddle.net/8Bznc/1/< /a>
I've already had a look through some posts and couldn't find what I was after. I'm designing something in PS at the moment and I can foresee an issue when it comes to coding the design into html+css.
Imagine my centre div, it's 960px
. It's going to have a semi-transparent .png
as a background. The design is “full width”
so this div will be contained in a larger div, set to 100% width. This is all ok until I get to the background on this outer div. It's also going to have a .png running the full width of the page. Problem is: I don't want it running through the middle, as it will result in the middle have a double thickness to it, if that makes sense?!
Basically, I need a way to either run a div either side that is elastic, or someway of stopping the background from running across the centre 960px
portion of the browser window.
I have NO idea how this can be achieved, apart from using JS to set widths, which I don’t really want to do.
Any ideas?
Ok, I’ve tried to get the basic issue here: http://jsfiddle.net/8Bznc/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在中心 div 上放置一个不透明的背景,这样其他背景就不会显示出来。
请参阅此处:http://jsfiddle.net/9bnHD/
You can just put a non-transparent background on the center div, so the other background doesn't show through.
See here: http://jsfiddle.net/9bnHD/
仅将
background-image
应用于包装div
。或者,如果中心和侧面需要有不同的图像,也可以为中心
div
指定不透明的background-color
。另外,您可以通过使用多个背景图像来伪造它。 演示
请记住,这在旧版本的 IE 中不起作用,但不是必需的背景透明度可以被视为优雅降级。
Apply the
background-image
only to the wrappingdiv
.Alternatively, if the center and sides need to have different images, give the center
div
a non-transparentbackground-color
as well.Also, you could fake it by using multiple
background-images
. DemoKeep in mind this won't work in old versions of IE, but something as non-essential as background transparency can be excepted as graceful degradation.