接上篇博文内容,完成小米商城首页的简单h5实战。
首先总结一下整个首页中htm+css可能涉及的知识点:首先使用最多的就是定位(position),我们要懂得相对定位和绝对定位的区别(近期会针对该元素总结一篇博文),其次另一个需要注意的就是元素的隐藏与悬停显示,需要通过visibility来设置。除此之外,可能还会涉及元素的选择器:nth-child()属性。做出的效果图如下(可能宽高上与原网页有细微差别):
本文先展示相关的css设置,最后展示html代码。
一、导航栏(nav-bar)
nav-bar.css
.nav-bar {
height: 100px;
}
.logo {
width: 100px;
height: 100px;
float: left;
position: relative;
}
.logo img{
border-radius: 30%;
position: absolute;
top: 22px;
}
.nav-content {
position: absolute;
width: 880px;
height: 100px;
}
.nav-content a{
color: #333;
font-size: 16px;
}
.nav-content a {
float: right;
display: block;
padding: 26px 10px 38px;
}
.nav-content a:hover {
color: #ff6700;
}
.nav-content .list {
position: absolute;
z-index: 1988;
top: 80px;
left: -210px;
width: 1406px;
height: 350px;
padding: 12px 0 0 30px;
background-color:#fff;
visibility: hidden;
box-shadow: 0 0 3px #999;
}
.nav-content li:hover .list {
position: absolute;
visibility: visible;
}
.nav-search {
position: relative;
top: 25px;
float: right;
width: 260px;
right: -96px;
}
.nav-search input:nth-child(1) {
width: 245px;
height: 50px;
border: none;
box-shadow: 0 0 3px rgb(107, 106, 106);
font-size: 16px;
}
.nav-search a {
position: relative;
line-height: 50px;
top: -52px;
left: 250px;
display: block;
width: 52px;
height: 52px;
border: none;
text-align: center;
box-shadow: 0 0 3px rgb(107, 106, 106);
font-size: 20px;
color: #333;
}
.nav-search a:hover {
background-color: #ff6700;
color: #fff;
}
二、内容区(content)
content.css
.content {
padding: 0;
margin: 0;
position: relative;
}
.content ul {
padding: 0;
}
.content-left {
position: absolute;
top: 3px;
float: left;
background-color: rgba(105,101,101,.6);
width: 234px;
height: 461px;
color: #fff;
z-index: 999;
}
.content-left a {
padding-left: 20px;
display: block;
position: relative;
color: rgba(255, 255, 255, 0.9);
line-height: 42px;
height: 42px;
width: 234px;
}
.content-left i {
display: inline-block;
position: absolute;
top: 13px;
left: 214px;
}
.content-left li:hover {
width: 234px;
background-color: #ff6700;
}
.content-right {
float: right;
width: 992px;
height: 460px;
background-color: #999;
position: relative;
}
.content-right img{
position: absolute;
top: -1px;
width: 1226px;
height: 460px;
left: -234px;
overflow:hidden;
}
.scroll li{
position: relative;
z-index: 30;
border: 2px solid transparent;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.795);
width: 5px;
height: 5px;
float: right;
bottom: -420px;
right: 20px;
margin-right: 5px;
}
.scroll li:hover {
position: relative;
z-index: 30;
border: 2px solid #999;
border-radius: 50%;
background-color