我在容器类中创建了两个div
框。放大和缩小页面时,div框的对齐方式会发生更改并相互冲突。我附上了HTML和CSS。我需要在放大和缩小时将div
框固定在容器类中。我被困在这里。有什么帮助吗?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type = "text/css">
*{
margin:0;
padding:0;
font-family:Arial, Helvetica, sans-serif;
}
body{
background-color:#e1e3e4;
}
.main{
width:90%;
margin: 0 auto;
}
header{
height:160px;
background-color:#3c948b;
}
.container{
background-color: #f3f3f3;
min-height:500px;
}
.content{
float:left;
position:relative;
top:10px;
left:10px;
border: 2px solid #111;
width:70%;
}
.panel{
position:relative;
float:left;
top:10px;
left:20px;
border: 2px solid #111;
width:330px;
}
</style>
</head>
<body>
<div class="main">
<header>
<h1>My personal blog</h1>
</header>
<div class="container">
<div class="content">
#content
</div>
<div class="panel">
#panel
</div>
</div>
</div>
</body>
</html>
最佳答案
如何除去浮子并用display: table
进行处理?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type = "text/css">
*{
margin:0;
padding:0;
font-family:Arial, Helvetica, sans-serif;
}
body{
background-color:#e1e3e4;
}
.main{
width:90%;
margin: 0 auto;
}
header{
height:160px;
background-color:#3c948b;
}
.container{
width: 100%;
display: table;
background-color: #f3f3f3;
min-height:500px;
}
.content{
display: table-cell;
top:10px;
border: 2px solid #111;
width:70%;
}
.panel{
display: table-cell;
top:10px;
border: 2px solid #111;
width:330px;
}
</style>
</head>
<body>
<div class="main">
<header>
<h1>My personal blog</h1>
</header>
<div class="container">
<div class="content">
#content
</div>
<div class="panel">
#panel
</div>
</div>
</div>
</body>
</html>