设置边缘 div 来填充剩余宽度
我发现了几个已经被问过的类似场景,但没有一个能够解决这个特定问题。我希望有人能帮忙!
连续三个div。中间的 div 居中,并且具有设定的宽度和宽度。高度。外部两个 div 必须扩展以填充窗口边缘和中心 div 边缘之间的剩余空间。像这样:
http://kthornbloom.com/example.jpg
*注意-我想用CSS解决它,但如果需要javascript,那就可以了
*note2-这样做的目的不是使中间的div居中,我知道有更好的方法可以做到这一点。目的是为了设计使用背景元素的网站,该背景元素需要是页面除中间之外的整个宽度。
I've found several SIMILAR scenarios that have been asked already, but none that solve this particular problem. I'm hoping someone can help!
Three divs in a row. The middle div is centered, and has a set width & height. The outer two divs must expand to fill the remaining space between the edge of the window, and the edge of the center div. Like this:
http://kthornbloom.com/example.jpg
*note- I'd like to solve it with CSS, but if javascript is required, that would be ok
*note2- The purpose of this isn't to center the middle div, I know there's better ways of doing that. The purpose is for the design of the site which uses a background element that needs to be the full width of the page except in the middle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅:http://jsfiddle.net/thirtydot/xhCXq/
HTML:
CSS :
我认为这很好地回答了你的问题,但这让我担心:
您确定您确实需要这样复杂的解决方案吗?也许更简单的东西:
http://jsfiddle.net/thirtydot/xhCXq/1/
See: http://jsfiddle.net/thirtydot/xhCXq/
HTML:
CSS:
I think that answers your question nicely, but this concerns me:
Are you sure you actually need a complicated solution like this? Maybe something simpler instead:
http://jsfiddle.net/thirtydot/xhCXq/1/
CSS不是动态语言,你不能用它来计算剩余空间。您可以使用 jQuery 来实现这一点。在下面的示例中,中间 div 将保持 400 像素,而剩余空间将在左右 div 之间分配。
检查工作示例 http://jsfiddle.net/M5Ghx/3/
CSS is not a dynamic language, you can't use it to calculate remaining space. You can use jQuery for that. In the example below Middle div will stay 400px while remaining space will be split between left and right divs.
Check working example at http://jsfiddle.net/M5Ghx/3/
不确定这是否有帮助,但我发现了这个有趣的技巧。似乎适用于 IE 8、IE 9、FireFox 3.6、FireFox 4 和 Safari 5(至少对于 Windows)。
然后,使用 z-index:10 将居中的 div 添加到顶部(使用您最喜欢的方法);使其“位于”其他元素之上。
Not sure if this helps, but I discovered this fun trick. Seems to work in IE 8, IE 9, FireFox 3.6, FireFox 4, and Safari 5 (for windows, at least).
Then, add your centered div over the top (using your favorite method), using z-index:10; to make it "on top of" the other elements.