我有一个“导航”div,它是一个浮动到页面左侧的链接列表。在它右边是一个“内容”div文本也向左浮动。当然,它们的高度取决于其中的内容。
因此,仅5个链接的“导航”div比多个段落“content”div短得多。 (这些是白色背景上的彩色框,这就是我试图排列它们的原因)
我想要的是将它们设置为相同的高度以便它们排成一行。当然我可以手动指定它们的像素高度,但是我希望这个CSS文件可以在多个HTML页面中使用,其中文本内容从2-5段落不等,并且手动指定将不起作用。
答案 0 :(得分:3)
请查看以下答案。
<强> HTML 强>
<div class="container clearfix">
<div class="sidebar">
<ul>
<li>link1</li>
<li>link1</li>
<li>link1</li>
<li>link1</li>
</ul>
</div>
<div class="content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</div>
<强> CSS 强>
.container{border:1px red solid; position:relative;}
.sidebar {float:left;width:150px;border:1px green solid;position:absolute;top:0;bottom:0;left:0;}
.sidebar ul{list-style:none;padding:0;margin:0;}
.content{float:left;width:300px;border:1px orange solid;margin-left:160px;}
.clearfix:before, .clearfix:after { content: " "; display: table; }
.clearfix:after { clear: both; }
.clearfix { *zoom: 1;}
下面是我的代码的小提琴。您可以通过我刚提到的一种方式来解决这个问题。