我正在尝试编写一个 CSS 两列布局。在我的代码中有三个<div>
标签。第一个<div>
标签包含另外两个<div>
标签。一种用于导航,一种用于内容。我将这些标签制作为浮动标签。这些标签没有问题。问题是,父<div>
标签有一个 2px 的边框,但它不会在屏幕周围呈现这个边框。
CSS 代码:
#wrap{
margin: 0 auto;
width: 900px;
border: 2px solid #ADA095;
}
#nav{
background-color: #DED8B9;
float: left;
width: 20%;
}
#content{
background-color: #EDE9DB;
float: right;
width: 80%;
}
HTML 代码:
<div id="wrap">
<div id="nav">
<h2>Sonnet Index</h2>
<ul>
<li><a href="#">Sonnet #1</a></li>
<li><a href="#">Sonnet #6</a></li>
<li><a href="#">Sonnet #11</a></li>
<li><a href="#">Sonnet #15</a></li>
<li><a href="#">Sonnet #18</a></li>
</ul>
</div>
<div id="content">
<h1>Shakespeare's Sonnet #18</h1>
<p>This is one of the most famous of the sonnets. It is referenced
in the film Dead Poets Society and gave names to the band The
Darling Buds and the book and television series The Darling Buds
of May. Read it and weep!</p>
<ul>
<li>Shall I compare thee to a summer's day?</li>
<li>Thou art more lovely and more temperate:</li>
<li>Rough winds do shake the darling buds of May,</li>
</ul>
<p class="copyright">See the
<a href="http://en.wikipedia.org/wiki/Shakespeare%27s_Sonnets">
Shakespeare's sonnets</a> Wikipedia article for more information
</p>
</div>
</div>
这是我的代码的输出。
但是,应该是这样——
提前致谢。