既然要让div浮动起来,就要用到CSS中的float属性!
先来说一说CSS中的float属性:
float 属性定义元素在哪个方向浮动。以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动。浮动元素会生成一个块级框,而不论它本身是何种元素。
如果浮动非替换元素,则要指定一个明确的宽度;否则,它们会尽可能地窄。
//默认是浮动到同一列的
float:left; //浮动到同一行
例如:(同一行)
<style>
.float{
float:left;
}
.question{
width:100px;
height:150px;
background-color:#666;
margin-top:30px;
margin-left:110px;
}
</style>
<div class="question float">
</div>
<div class="question float">
</div>
例如: (同一列)
<style>
.question{
width:100px;
height:150px;
background-color:#666;
margin-top:30px;
margin-left:110px;
}
</style>
<div class="question">
</div>
<div class="question">
</div>
注意:
一个标签可以有多个class名字,不过再调用多个class名称的时候,中间用空格隔开。