天气预报案例
步骤
- 获取北京市天气数据,展示
- 搜索城市列表,展示
- 点击城市,显示对应天气数据
index.css代码
html,
body {
height: 100%;
}
body {
background-image: linear-gradient(135deg, #50B1FF 0%, #1F57D6 100%);
}
.container {
width: 1200px;
margin: 0 auto;
height: 100%;
}
/* 顶部 */
.top-box {
display: flex;
padding: 50px;
justify-content: space-between;
}
/* 日期 */
.top-box .title .data {
color: white;
margin-right: 20px;
}
/* 农历 */
.top-box .title .calendar {
opacity: .72;
}
/* 搜索区域 */
.search-box {
display: flex;
justify-content: space-between;
align-items: center;
}
.search-box .location {
display: flex;
align-items: center;
margin-right: 20px;
font-size: 16px;
}
.search-box .location img {
width: 20px;
height: 20px;
margin-right: 7.1px;
}
.search-box .search-city {
width: 234px;
height: 32px;
border: none;
border-radius: 16px;
padding-left: 10px;
background-color: rgba(255, 255, 255, .2);
color: white;
font-size: 14px;
}
.search {
position: relative;
}
/* 搜索列表 */
.search-list {
width: 100%;
height: 200px;
overflow-y: scroll;
background-color: #fff;
position: absolute;
left: 0;
top: 40px;
display: none;
}
.search-list.show{
display: block;
}
.search-list::-webkit-scrollbar{
display: none;
}
.search-list li{
color: black;
font-size: 14px;
padding: 15px 10px;
}
.search-list li:hover{
background-color: lightgray;
}
/* 当前天气 */
.weather-box {
display: flex;
padding-left: 50px;
align-items: flex-end;
}
.weather-box .tem-box {
margin-right: 42px;
display: flex;
flex-direction: column;
}
.weather-box .tem-box .temp span{
font-size: 90px;
display: inline-block;
height: 100px;
margin-bottom: 10px;
line-height: 100px;
}
.climate-box .air {
display: inline;
padding: 5px 10px;
height: 32px;
border-radius: 16px;
background: #65D45A;
text-align: center;
line-height: 32px;
font-family: PingFangSC-Medium;
font-size: 18px;
color: #FFFFFF;
letter-spacing: 0;
font-weight: 500;
}
.climate-box .weather-list {
display: flex;
align-items: flex-end;
margin-top: 21px;
margin-bottom: 28px;
}
.climate-box .weather-list li img {
width: 20px;
height: 20px;
}
.climate-box .weather-list li {
margin-right: 20px;
}
.climate-box .weather-list li,
.climate-box .weather-list span {
display: flex;
align-items: center;
font-size: 16px;
}
/* 今日详细天气 */
.today-weather{
display: flex;
padding-left: 50px;
}
.today-weather .range-box,
.today-weather .range {
font-size: 16px;
}
.today-weather .sun-list {
display: flex;
align-items: center;
margin-left: 50px;
}
.today-weather .sun-list li {
font-size: 16px;
margin-right: 42px;
}
/* 周天气预报 */
.week-weather-box {
height: 382px;
border-radius: 10px;
background-color: #fff;
width: 1039px;
margin: 30px auto;
padding: 30px;
}
.week-weather-box .title {
font-size: 20px;
color: #3A475A;
letter-spacing: 0;
font-weight: 600;
}
/* 列表 */
.week-wrap {
display: flex;
margin: 0 auto;
margin-top: 30px;
}
.week-wrap .item {
width: 150px;
height: 254px;
cursor: pointer;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 30px;
}
.week-wrap .item:hover {
background: #F7FAFF;
border-radius: 10px;
}
.week-wrap .item span{
color: #393F48;
}
.week-wrap .item .date-box {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 4px;
}
.week-wrap .item .date-box .dateFormat {
font-size: 16px;
color: #393F48;
letter-spacing: 0;
text-align: center;
font-weight: 400;
}
.week-wrap .item .date-box .date {
font-size: 16px;
color: #88909D;
letter-spacing: 0;
text-align: center;
font-weight: 400;
}
.week-wrap .item img {
width: 46px;
height: 46px;
margin: 12px 0 12px;
}
.week-wrap .item .weather {
font-size: 16px;
color: #393F48;
letter-spacing: 0;
text-align: center;
font-weight: 400;
margin-bottom: 4px;
}
.week-wrap .item .temp {
font-size: 14px;
color: #393F48;
letter-spacing: 0;
text-align: center;
font-weight: 500;
margin-bottom: 10px;
}
.week-wrap .item .wind span {
font-size: 14px;
color: #676C74;
letter-spacing: 0;
text-align: center;
font-weight: 400;
}
reset.css代码
* {
box-sizing: border-box;
font-size: 18px;
;
color: white;
}
body,
ul,
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-size: 100%;
font-weight: normal;
}
a {
text-decoration: none;
}
ul {
list-style: none;
}
img {
border: 0px;
}
input {
appearance: none;
outline: none;
}
input::-we