这个简单的 HTML、CSS 布局有什么问题?
What is the issue with this simple HTML, CSS layout?
虽然这是一个非常简单的 HTML、CSS 布局,但我遇到了这个问题。它看起来不像我想要的那样。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
body {
margin: 0;
padding: 100px;
width: 100%;
}
div.container {
border: 3px red solid;
padding: 10px;
display: block;
width: 1000px;
}
div.left, div.right {
float: left;
margin: 0 10px;
}
div.left {
background: blue;
height: 300px;
width: 300px;
}
div.right {
background: green;
width: 300px;
height: 300px;
}
</style>
</head>
<body>
<div class="container">This is the main container
<div class="left">This is the left side</div>
<div class="right">This is the right side</div>
</div>
I want to know why left and right blocks overlaps the container element?
</body>
</html>
为什么左右块与 container
元素重叠?
我上传了 Chrome 在 PC 上执行的代码的屏幕截图。这是 Google 驱动器预览 link:https://drive.google.com/open?id=0B4av_i4gqoZmRFpXbzVZekR0aGs&authuser=0
提前致谢。
在您的 CSS 文件中添加此样式:
.container:before,
.container:after {
display: table;
content: " ";
}
.container:after {
clear: both;
}
这应该可以解决问题![=11=]
虽然这是一个非常简单的 HTML、CSS 布局,但我遇到了这个问题。它看起来不像我想要的那样。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
body {
margin: 0;
padding: 100px;
width: 100%;
}
div.container {
border: 3px red solid;
padding: 10px;
display: block;
width: 1000px;
}
div.left, div.right {
float: left;
margin: 0 10px;
}
div.left {
background: blue;
height: 300px;
width: 300px;
}
div.right {
background: green;
width: 300px;
height: 300px;
}
</style>
</head>
<body>
<div class="container">This is the main container
<div class="left">This is the left side</div>
<div class="right">This is the right side</div>
</div>
I want to know why left and right blocks overlaps the container element?
</body>
</html>
为什么左右块与 container
元素重叠?
我上传了 Chrome 在 PC 上执行的代码的屏幕截图。这是 Google 驱动器预览 link:https://drive.google.com/open?id=0B4av_i4gqoZmRFpXbzVZekR0aGs&authuser=0
提前致谢。
在您的 CSS 文件中添加此样式:
.container:before,
.container:after {
display: table;
content: " ";
}
.container:after {
clear: both;
}
这应该可以解决问题![=11=]