帮我写一个天气预报静态网页
时间: 2023-08-20 20:28:56 浏览: 288
好的,我可以提供一个简单的天气预报静态网页的示例。这个示例使用 HTML 和 CSS 来显示天气信息。
HTML 代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>天气预报</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<h1>天气预报</h1>
</header>
<main>
<section class="city">
<h2>城市</h2>
<select>
<option>北京</option>
<option>上海</option>
<option>广州</option>
<option>深圳</option>
</select>
</section>
<section class="weather">
<h2>天气</h2>
<div class="current-weather">
<div class="weather-icon">
<img src="https://www.weatherbit.io/static/img/icons/r01d.png">
</div>
<div class="temperature">
<h3>20°C</h3>
</div>
<div class="description">
<p>小雨</p>
</div>
</div>
<div class="forecast">
<h3>未来天气</h3>
<div class="forecast-item">
<div class="forecast-icon">
<img src="https://www.weatherbit.io/static/img/icons/r01d.png">
</div>
<div class="forecast-date">
<p>2021-05-01</p>
</div>
<div class="forecast-temperature">
<p>20°C</p>
</div>
<div class="forecast-description">
<p>小雨</p>
</div>
</div>
<div class="forecast-item">
<div class="forecast-icon">
<img src="https://www.weatherbit.io/static/img/icons/c01d.png">
</div>
<div class="forecast-date">
<p>2021-05-02</p>
</div>
<div class="forecast-temperature">
<p>24°C</p>
</div>
<div class="forecast-description">
<p>晴</p>
</div>
</div>
<div class="forecast-item">
<div class="forecast-icon">
<img src="https://www.weatherbit.io/static/img/icons/r01d.png">
</div>
<div class="forecast-date">
<p>2021-05-03</p>
</div>
<div class="forecast-temperature">
<p>22°C</p>
</div>
<div class="forecast-description">
<p>小雨</p>
</div>
</div>
</div>
</section>
</main>
<footer>
<p>© 2021 天气预报</p>
</footer>
</body>
</html>
```
CSS 代码:
```css
header {
background-color: #4285F4;
color: #FFFFFF;
padding: 20px;
text-align: center;
}
main {
margin: 20px;
}
section {
margin-bottom: 20px;
}
select {
border: none;
border-radius: 4px;
font-size: 16px;
padding: 8px;
}
.current-weather {
display: flex;
flex-direction: row;
align-items: center;
}
.weather-icon {
flex: 1;
}
.temperature {
flex: 2;
text-align: center;
}
.description {
flex: 1;
}
.forecast {
display: flex;
flex-direction: column;
}
.forecast-item {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 10px;
}
.forecast-icon {
flex: 1;
}
.forecast-date {
flex: 2;
}
.forecast-temperature {
flex: 1;
text-align: center;
}
.forecast-description {
flex: 1;
}
```
这个示例包括一个标题、一个城市选择器、一个当前天气信息和一个未来天气预报。你可以根据需要修改 HTML 和 CSS 代码。另外,这个示例的天气数据是使用 Weatherbit API 获取的,你需要在代码中替换为你自己的 API。
阅读全文