我正在尝试在导航栏下方创建一列内容,以使内容的宽度与导航栏的宽度完全匹配。事实证明这比我预期的要困难。
鉴于这样的事情:
<div id="Wrapper">
<!-- nav should all be on one line. #Wrapper should stretch to hold it-->
<nav>
<ul>
<li>link 1</li>
<li>link 2</li>
<li>etc</li>
</ul>
</nav>
<!-- article should not stretch #Wrapper, even if it is wider than nav -->
<article>
<h1>title</h1>
<p>This should be constrained to nav's width,
even if by all rights it would be wider</p>
</article>
</div>
我正在尝试实现这样的目标:
+-----------------------------+
| +-------------------+ |
| |+-----------------+| |
| ||link 1 link 2 etc|| |
| |+-----------------+| |
| |+-----------------+| |
| ||TITLE || |
| ||this should be || |
| ||constrained to || |
| ||nav's width, even|| |
| ||if by all rights || |
| ||it would be wider|| |
| |+-----------------+| |
| +-------------------+ |
+-----------------------------+
我可以在#Wrapper 上设置固定宽度,但是如果字体发生变化或缩放,那么导航栏将与文章的宽度不匹配。
另一方面,我找不到一种方法来允许导航栏拉伸#Wrapper,同时防止文章进一步拉伸。
另一方面,如果有某种方法可以使元素与兄弟的宽度匹配,我可以完全取消#Wrapper。