【发布时间】:2015-06-17 13:12:43
【问题描述】:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Responsive</title>
<style>
.city {
float: left;
margin: 5px;
padding: 15px;
width: 100%;
height: 300px;
border: 1px solid black;
}
.city2 {
float: left;
margin: 5px;
padding: 15px;
width: 100%;
height: 100px;
border: 1px solid red;
}
</style>
</head>
<body background="page-bg.jpg">
<h1>W3Schools Demo</h1>
<h2>Resize this responsive page!</h2>
<div style="width:100%">
<div style="width:21%;" >
<div class="city2">
<h2>London</h2>
<p>London is the capital city of England.</p>
</div>
</div>
<div style="width:21%;float:left;">
<div class="city2">
<h2>Paris</h2>
</div>
</div>
<div style="width:21%;">
<div class="city2">
<h2>Tokyo</h2>
</div>
</div>
<div style="width:21%;">
<div class="city2">
<h2>Istanbul</h2>
</div>
</div>
</div>
<div style="width:100%">
<div style="width:33.3%">
<div class="city">
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
</div>
</div>
<div style="width:33.3%">
<div class="city">
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>
</div>
<div style="width:33.3%">
<div class="city">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.</p>
</div>
</div>
</div>
</body>
</html>
上面是我的代码,它在第 1 行有 4 个 div,在第 2 行有 3 个 div。我试图让 div 响应。为此,代码中提到了 city,city2 的 css。呈现代码时,前四个 div 不是直线。另外,当我调整窗口大小时,排列是响应式的,但是这 4 个 div 前面有空白。请帮助我如何让它们响应并占据屏幕的各个维度。
【问题讨论】:
标签: html css responsive-design