目录
尴尬场景
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.main{
padding: 10px;
border: #000000 1px solid;
}
.sub1{
width: 30%;
height: 100px;
float: left;
border: #000000 1px solid;
}
.sub2{
width: 65%;
height: 100px;
float: right;
border: #000000 1px solid;
}
</style>
</head>
<body>
<div class="mui-content">
<div class="main">
<div class="sub1">
</div>
<div class="sub2">
</div>
</div>
</div>
</body>
</html>
解决方法1
给父标签添加overflow:hidden属性
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.main{
padding: 10px;
border: #000000 1px solid;
overflow: hidden;
}
.sub1{
width: 30%;
height: 100px;
float: left;
border: #000000 1px solid;
}
.sub2{
width: 65%;
height: 100px;
float: right;
border: #000000 1px solid;
}
</style>
</head>
<body>
<div class="mui-content">
<div class="main">
<div class="sub1">
</div>
<div class="sub2">
</div>
</div>
</div>
</body>
</html>
解决方法2
父级标签内添加清除浮动的子级标签
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.main{
padding: 10px;
border: #000000 1px solid;
}
.sub1{
width: 30%;
height: 100px;
float: left;
border: #000000 1px solid;
}
.sub2{
width: 65%;
height: 100px;
float: right;
border: #000000 1px solid;
}
.sub3{
clear: both;
}
</style>
</head>
<body style="padding: 20px">
<div class="mui-content">
<div class="main">
<div class="sub1">
</div>
<div class="sub2">
</div>
<div class="sub3"></div>
</div>
</div>
</body>
</html>
解决方法3
如果知道子级标签的高度的话,那就给父级添加固定高度吧
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.main{
padding: 10px;
border: #000000 1px solid;
height: 120px;
}
.sub1{
width: 30%;
height: 100px;
float: left;
border: #000000 1px solid;
}
.sub2{
width: 65%;
height: 100px;
float: right;
border: #000000 1px solid;
}
</style>
</head>
<body style="padding: 20px">
<div class="mui-content">
<div class="main">
<div class="sub1">
</div>
<div class="sub2">
</div>
</div>
</div>
</body>
</html>