css中width为auto或者100%的区别四个理论:某div不显示设置宽度那么width为auto;某div的width在默认情况设置的是盒子模型中content的值;某div的width为100%表示的是此div盒子内容部分的宽度为其父元素的宽度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="../css/layout2.css">
</head>
<body>
<div class="container">
<div class="content1">
</div>
<div class="content2">
</div>
</div>
</body>
</html>
* {
padding: 0;
margin: 0;
}
.container {
width: 100%;
height: 1000px;
}
.content1{
background: yellowgreen;
width: auto;
height: 100px;
padding-left: 100px;
}
.content2 {
background: gold;
width: 100%;
height: 100px;
padding-left: 100px;
}