代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多个元素在一行显示</title>
<link rel="stylesheet" href="">
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
.wrap {
font-size: 0%;
}
.content1 {
width: 200px;
height: 200px;
background: yellow;
font-size: 14px;
display: inline-block;
*display: inline; /* css hack ie浏览器可识别*/
*zoom: 1; /* 出发 css hack 的layout */
}
.content2 {
width: 200px;
height: 200px;
background: rosybrown;
font-size: 14px;
display: inline-block;
*display: inline; /* css hack ie浏览器可识别*/
*zoom: 1; /* 出发 css hack 的layout */
}
/*
display: inline-block 在 ie6,7 下不兼容的方法解决办法 (css hack 兼容)
*display:inline;
*zoom: 1;
*/
.mian {
overflow: hidden; /* 清楚浮动 */
}
.left {
float: left;
width: 200px;
height: 200px;
background: salmon;
}
.right {
float: left;
width: 200px;
height: 200px;
background: greenyellow;
}
</style>
<body>
<!-- 方法 1-->
<div class="wrap">
<div class="content1"> 11111</div>
<div class="content2"> 22222</div>
</div>
<!-- 方法2 -->
<div class="main">
<div class="left"> left</div>
<div class="right"> right</div>
</div>
</body>
</html>