我想要一个 CSS 布局,其中左侧有一个 100 像素的边栏。整个网页的宽度必须为 400 像素。以下不同方法之间的优缺点和一般区别是什么?
方法一
#container {
width: 400px;
}
#left {
float: left;
width: 100px;
}
#main {
float: left;
width: 300px;
}
方法二
#container {
width: 400px;
}
#left {
float: left;
width: 100px;
}
#main {
display: block;
margin-left: 100px;
}
最佳答案
您应该使用方法 1,
假设#main 是一个 div,它已经有一个 display:block 的属性;默认情况下。
关于css - 多列布局 : Pros and cons of float vs display:block?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8785752/