css - 如何使用 div 将元素定位在同一级别,以便页面不会分崩离析?

标签 css html css-float

我使用 div 并排放置了 3 个元素。问题是其中之一会根据用户输入动态增长。如果它变得太大,所有元素都会落入错误的位置,整个页面都会被毁容。如何在不使用表格的情况下解决此问题。

最佳答案

您可以使用 width CSS属性。并排 float 元素,然后每个元素的内容将具有您将为每个元素设置的 width

html

<div class="box" id="first">content</div>
<div class="box" id="second">content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content content </div>
<div class="box" id="third">content content content content content content content content content content content content content content content content content content </div>

CSS

.box {float:left; width:200px;}
#first {background:red;}
#second {background:blue;}
#third {background:green;}

演示: http://jsfiddle.net/K9K6B/

关于css - 如何使用 div 将元素定位在同一级别,以便页面不会分崩离析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4843788/

相关文章:

html - 如何收缩包装 float 内容?

html - CSS Position 图片比容器大

c# - GridView 列不断缩小

javascript - 用于填写表格的单选按钮

html - HTML 有 "Include/Import"函数吗?

jquery - 如何在将鼠标悬停在 div 上时放大它?

html - 我是刚刚发现了 CSS 中的错误还是忽略了什么?

html - dom 元素 id 相等

css - 为什么我的页面无法在 Internet Explorer 6 中正确显示?

html - CSS:100% div 在移动设备上未显示为 100%