最近在学习前段,我们来写一个品优购网页来练习一下静态网页的写法。
在制作标题党时候,要设置好title、description和Keywords来改善SOE结果,以便搜索引擎更好的搜索我们的网页。
<title>品优购 </title>
<title>品优购-正品低价、品质保障、配送及时、轻松购物!</title>
<meta name="description"
content="品优购-专业的综合网上购物商城,为您提供正品低价的购物选择、优质便捷的服务体验。商品来自全球数十万品牌商家,囊括家电、手机、电脑、服装、居家、母婴、美妆、个护、食品、生鲜等丰富品类,满足各种购物需求。">
<meta name="Keywords" content="网上购物,网上商城,家电,手机,电脑,服装,居家,母婴,美妆,个护,食品,生鲜,京东">
看一下网页的布局网页,可以从垂直方向和水平方向进行,从垂直方向看,网页布局可以分为三大部分,网页的抬头、主体内容,以及最下方的版权页,由于抬头和版权页会在其他页面中反复使用,因此可以率先制作,并将公共部分储存起来。
我们可以看出,所有的版式居中显示,因此可以设置一个版心来规范版式。
.w {
width: 1200px;
margin: 0 auto;
}
在制作抬头的时候,可以拆解为三大块。 最上方的导航模块。我们制作一个盒子shortcut来储存导航栏内的所有信息,然后制作两个小盒子fl、fr利用浮动使他们出现在,分别用于注册及登录功能和网页导航,我们用链接来完成登陆所需的按钮,用li来储存导航按钮:
<!-- 快捷导航start -->
<section class="shortcut">
<div class="w">
<div class="fl">
<ul>
<li>品优购欢迎您! </li>
<li><a href="#">登录 </a>
<a href="register.html" class="style-red">快捷注册</a>
</li>
</ul>
</div>
<div class="fr">
<ul>
<li>我的订单</li>
<li></li>
<li class="arrow-icon">我的品优购
</li>
<li></li>
<li>品优购会员</li>
<li></li>
<li>企业采购</li>
<li></li>
<li class="arrow-icon">关注品优购
</li>
<li></li>
<li class="arrow-icon">客户服务
</li>
<li></li>
<li class="arrow-icon">网站导航
</li>
</ul>
</div>
</div>
</section>
<!-- 快捷导航end -->
第二个盒子header要包搜索栏以及购物车模块,我们分别用三个盒子完成他们都功能,并用浮动完成水平布局。
<!-- 头部模块start -->
<header class="header w">
<!-- logo模块 -->
<div class="logo">
<h1><a href="index.html" title="品优购商城">品优购商城</a></h1>
</div>
<!-- search搜索模块 -->
<div class="search">
<input type="search" name="" id="" placeholder="开发语言">
<button>搜索</button>
</div>
<!-- hotwords模块 -->
<div class="hotwords">
<a href="#" class="style-red">优惠购首发</a>
<a href="#">亿元优惠</a>
<a href="#">9.9团购</a>
<a href="#">满99减30</a>
<a href="#">办公用品</a>
<a href="#">电脑</a>
<a href="#">通信</a>
</div>
<!-- 购物车模块 -->
<div class="shopcar">我的购物车<i class="count">8</i></div>
</header>
第三个盒子nav用来放商品分类信息,这里需要用两个两个盒子以两种不同的方式展示产品分类,尽管全部产品分类dropdown会延伸到下方区域,但作为一个整体,我们最好先完成制作。
<nav class="nav">
<div class="w">
<div class="dropdown">
<div class="dt">全部商品分类</div>
<div class="dd">
<ul>
<li><a href="#">家用电器</a></li>
<li><a href="list.html">手机、数码、通信</a></li>
<li><a href="#">电脑、办公</a></li>
<li><a href="#">家居、家具、家装、厨具</a></li>
<li><a href="#">男装、女装、童装、内衣</a></li>
<li><a href="#">个户化妆、清洁用品、宠物</a></li>
<li><a href="#">鞋靴、箱包、珠宝、奢侈品</a></li>
<li><a href="#">运动户外、钟表</a></li>
<li><a href="#">汽车、汽车用品</a></li>
<li><a href="#">母婴、玩具乐器</a></li>
<li><a href="#">食品、酒类、生鲜、特产</a></li>
<li><a href="#">医药保健</a></li>
<li><a href="#">图书、音像、电子书</a></li>
<li><a href="#">彩票、旅行、充值、票务</a></li>
<li><a href="#">理财、众筹、白条、保险</a></li>
</ul>
</div>
</div>
<div class="navitems">
<ul>
<li><a href="#">服装城</a></li>
<li><a href="a">美妆馆</a></li>
<li><a href="a">传智超市</a></li>
<li><a href="a">全球购</a></li>
<li><a href="a">闪购</a></li>
<li><a href="a">团购</a></li>
<li><a href="a">拍卖</a></li>
<li><a href="a">有趣</a></li>
</ul>
</div>
</div>
</nav>
<!-- nav模块制作end -->
css代码。
font-family: 'iconfont';
src: url('../css/font/iconfont.woff2?t=1688128745748') format('woff2'),
url('../css/font/iconfont.woff?t=1688128745748') format('woff'),
url('../css/font/iconfont.ttf?t=1688128745748') format('truetype');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* 版心 */
.w {
width: 1200px;
margin: 0 auto;
}
.fl {
float: left;
}
.fr {
float: right;
}
.style-red {
color: #c81623;
}
/* 快捷导航 */
.shortcut {
height: 30px;
line-height: 30px;
background-color: #f1f1f1;
}
.shortcut .w .fl ul li {
float: left;
}
.shortcut .w .fr ul li {
float: left;
}
.shortcut .fr ul li:nth-child(even) {
width: 1px;
height: 12px;
background-color: #666;
margin: 10px 15px 0;
}
.arrow-icon::after {
content: "\e615";
font-family: "iconfont";
margin-left: 6px;
}
/* 头部制作 */
.header {
position: relative;
height: 105px;
background-color: pink;
}
.header .logo {
width: 171px;
top: 25px;
height: 61px;
/* background-color: blue; */
position: absolute;
}
.logo a {
display: block;
width: 171px;
height: 61px;
background: url(../images/logo.png);
font-size: 0
}
.search {
width: 540px;
height: 35px;
border: 2px solid red;
position: absolute;
left: 350px;
top: 30px
}
.search input {
float: left;
height: 35px;
width: 455px;
padding-left: 5px;
}
.search button {
float: right;
width: 85px;
height: 35px;
background-color: red;
}
.hotwords {
position: absolute;
left: 355px;
top: 70px;
}
.hotwords a {
margin-left: 10px;
}
.shopcar {
position: absolute;
width: 140px;
height: 35px;
background-color: #f7f7f7;
top: 30px;
right: 65px;
border: 1px solid #dfdfdf;
line-height: 35px;
text-align: center;
}
.shopcar::before {
content: "\e826";
font-family: "iconfont";
margin-right: 4px;
}
.shopcar::after {
content: '\e840';
font-family: "iconfont";
margin-left: 4px;
}
.shopcar .count {
position: absolute;
top: -5px;
left: 105px;
height: 14px;
line-height: 14px;
color: #f1f1f1;
background-color: #c81623;
padding: 0 5px;
border-radius: 7px 7px 7px 0;
}
.nav {
height: 45px;
border-bottom: 2px #b1191a solid;
}
.nav .dropdown {
float: left;
}
.nav .dropdown .dt {
color: white;
width: 220px;
height: 45px;
background-color: #b1191a;
font-size: 16px;
line-height: 45px;
text-align: center;
}
.nav .dropdown .dd {
width: 220px;
height: 465px;
background-color: #c81623;
}
.nav .dropdown .dd ul li {
height: 31px;
}
.nav .dropdown .dd ul li a {
color: #dfdfdf;
line-height: 31px;
font-size: 14px;
margin-left: 10px;
}
.nav .dropdown .dd ul li:hover {
background-color: white;
margin-left: 2px;
}
.nav .dropdown .dd ul li a::after {
content: '\e840';
font-family: "iconfont";
float: right;
margin-right: 10px;
}
.navitems ul li {
float: left;
text-align: center;
}
.navitems ul li a {
line-height: 40px;
display: block;
font-size: 16px;
width: 117px;
}