导航栏背景填充屏幕宽度,同时所有内容都在最小宽度和最大宽度值内
我正在创建一个流畅的网站设计,并指定 min-width
和 max-width
值,但是,我希望导航栏背景从一侧延伸屏幕到另一个屏幕(不受最大宽度限制),同时将其中的所有
元素以及所有其他屏幕内容保持在指定宽度内。此外,我还想设置页面的最小边距(例如16px),以便内容和页面边缘之间始终存在间隙。
理想情况下如下图所示:
将所有内容包含在 min-width
和 中的最佳方法是什么max-width
值,同时允许导航栏背景拉伸到屏幕宽度。另外,有没有一种方法可以使用 margin-left: auto
并保持最小边距值?每当我尝试这样做时,我只能得到其中之一。
感谢您提前提供的任何帮助。
I'm creating a fluid website design and am specifying min-width
and max-width
values, however, I'd like the navigation bar background to extend from one side of the screen to the other (not be constrained by the max width), whilst keeping all of the <li>
elements in it and all other screen content within the specified widths.
Furthermore, I would also like to set a minimum margin for the page (e.g. 16px) so that there is always a gap between the content and the edge of the page.
Ideally as in the image below:
What's the best way to go about containing everything inside the min-width
and max-width
values, whilst allowing the navbar background to stretch to the screen width. Also, is there a way I can use margin-left: auto
and yet keep a minimum margin value? Whenever I've tried to do this I can only get one or the other.
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种不同的方法可以做到这一点,但是这个 jsFiddle 说明了我将如何做到这一点:http://jsfiddle。净/joshnh/UDwcp/
There are a few different ways to do it, but this jsFiddle illustrates how I would do it: http://jsfiddle.net/joshnh/UDwcp/