首页 > 代码库 > 第31章 项目实战-PC端固定布局7
第31章 项目实战-PC端固定布局7
第31 章项目实战-PC 端固定布局[7]
学习要点:
1.侧栏制作
2.详细代码
本章主要开始使用学习用HTML5 和CSS3 来构建Web 页面,第一个项目采用PC 端
固定布局来实现。
一.侧栏制作
本节课,主要设计一下内容页面的侧栏部分,分三个小块。经过思考,侧栏会包含一些
图片,而主要部分也会包含图片,那么侧栏放在左边可能会和主栏的图片冲突导致不协调,
所以,我们把侧栏更换到右边。
//实际上,还去掉了高度,让其自适应
#container {
width: 1263px;
margin: 30px auto;
}
#container .sidebar {
width: 340px;
float: right;
}
//自适应后,footer 需要clear:both
#footer {
clear:both;
position: relative;
top: 20px;
}
以下三张图片,是连续在一列的,为了方便观看,分别截图。
二.详细代码
//HTML 部分
<div id="container">
<aside class="sidebar">
<div class="sidebox recommend">
<h2>景点推荐</h2>
<div class="tag">
<a href="http://www.mamicode.com/###">曼谷(12)</a>
<a href="http://www.mamicode.com/###">东京(5)</a>
<a href="http://www.mamicode.com/###">西双版纳(8)</a>
<a href="http://www.mamicode.com/###">漓江(16)</a>
<a href="http://www.mamicode.com/###">呼伦贝尔(4)</a>
<a href="http://www.mamicode.com/###">首尔(9)</a>
<a href="http://www.mamicode.com/###">巴厘岛(15)</a>
<a href="http://www.mamicode.com/###">土耳其(22)</a>
<a href="http://www.mamicode.com/###">夏威夷(5)</a>
<a href="http://www.mamicode.com/###">巴厘岛(11)</a>
<a href="http://www.mamicode.com/###">毛里求斯(7)</a>
<a href="http://www.mamicode.com/###">吉普岛(4)</a>
<a href="http://www.mamicode.com/###">希腊(18)</a>
<a href="http://www.mamicode.com/###">法瑞意(8)</a>
<a href="http://www.mamicode.com/###">马尔代夫(9)</a>
<a href="http://www.mamicode.com/###">新西兰(16)</a>
<a href="http://www.mamicode.com/###">埃及(11)</a>
<a href="http://www.mamicode.com/###">迪拜(14)</a>
<a href="http://www.mamicode.com/###">斯里兰卡(7)</a>
<a href="http://www.mamicode.com/###">麦哈顿(3)</a>
<a href="http://www.mamicode.com/###">大阪(15)</a>
</div>
</div>
<div class="sidebox hot">
<h2>热卖旅游</h2>
<div class="figure">
<figure>
<img src="http://www.mamicode.com/img/hot1.jpg" alt="曼谷-芭提雅6 日游">
<figcaption>曼谷-芭提雅6 日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot2.jpg" alt="马尔代夫双鱼6 日游">
<figcaption>马尔代夫双鱼6 日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot3.jpg" alt="海南双飞5 日游">
<figcaption>海南双飞5 日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot4.jpg" alt="富山大阪东京8 日游">
<figcaption>富山大阪东京8 日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot5.jpg" alt="法瑞意德12 日游">
<figcaption>法瑞意德12 日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot6.jpg" alt="巴厘岛6 日半游">
<figcaption>巴厘岛6 日半游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot7.jpg" alt="塞舌尔迪拜9 日游">
<figcaption>塞舌尔迪拜9 日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot8.jpg" alt="花样土耳其10 日游">
<figcaption>花样土耳其10 日游</figcaption>
</figure>
</div>
</div>
<div class="sidebox treasure">
<h2>旅游百宝箱</h2>
<div class="box">
<a href="http://www.mamicode.com/###" class="trea1">天气预报</a>
<a href="http://www.mamicode.com/###" class="trea2">火车票查询</a>
<a href="http://www.mamicode.com/###" class="trea3">航空查询</a>
<a href="http://www.mamicode.com/###" class="trea4">地铁线路查询</a>
</div>
</div>
</aside>
<div class="list">
list
</div>
</div>
//CSS 部分
#container {
width: 1263px;
margin: 30px auto;
}
#container .sidebar {
width: 340px;
float: right;
}
#container .sidebox {
border: 1px solid #eee;
margin: 0 0 10px 0;
text-align: center;
}
#container .sidebox h2 {
font-size: 20px;
font-weight: normal;
letter-spacing: 1px;
height: 40px;
line-height: 40px;
text-indent: 10px;
background-color: #fafafa;
color: #666;
text-align: left;
}
#container .tag {
padding: 10px 0;
}
#container .tag a {
display: inline-block;
margin: 2px 0;
width: 100px;
height: 35px;
line-height: 35px;
color: #999;
background-color: #eee;
text-align: left;
text-indent: 8px;
}
#container .tag a:hover {
background-color: #458b00;
color: #fff;
}
#container .figure {
padding: 10px 0;
}
#container .hot figure {
display: inline-block;
color: #666;
padding: 4px;
}
#container .box {
padding: 10px 0;
}
#container .box a {
display: inline-block;
margin: 2px 0;
width: 150px;
height: 40px;
line-height: 40px;
color: #999;
background-color: #eee;
text-align: left;
text-indent: 35px;
}
#container .box a.trea1 {
background: #eee url(../img/trea1.png) no-repeat 10px center;
}
#container .box a.trea2 {
background: #eee url(../img/trea2.png) no-repeat 10px center;
}
#container .box a.trea3 {
background: #eee url(../img/trea3.png) no-repeat 10px center;
}
#container .box a.trea4 {
background: #eee url(../img/trea4.png) no-repeat 10px center;
}
#container .list {
width: 900px;
float: left;
}
代码:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>项目实战--PC端固定布局</title>
<link rel="stylesheet" href="http://www.mamicode.com/css/basic.css">
<link rel="stylesheet" href="http://www.mamicode.com/css/style.css">
</head>
<body>
<header id="header">
<div class="center">
<h1 class="logo">瓢城旅行社</h1>
<nav class="link">
<h2 class="none">网站导航</h2>
<ul>
<li class="active"><a href="http://www.mamicode.com/index.html">首页</a></li>
<li><a href="http://www.mamicode.com/information.html">旅游资讯</a></li>
<li><a href="http://www.mamicode.com/###">机票订购</a></li>
<li><a href="http://www.mamicode.com/###">风景欣赏</a></li>
<li><a href="http://www.mamicode.com/###">公司简介</a></li>
</ul>
</nav>
</div>
</header>
<div id="search">
<div class="center"></div>
<input type="text" class="search" placeholder="请输入旅游景点或城市">
<button class="button">搜索</button>
</div>
<div id="tour">
<section class="center">
<h2>热门旅游</h2>
<p>国内旅游、国外旅游、自助旅游、自驾旅游、油轮签证、主题旅游等各种最新热门旅游推荐</p>
</section>
<figure>
<img src="http://www.mamicode.com/img/tour1.jpg" >
<figcaption><strong class="title"><曼谷-芭提雅6日游></strong> 包团特惠,超丰富景点,升级1晚国五,无自费,更赠送600元/成人自费券</figcaption>
<div>
<em class="sat">满意度 77%</em>
<span class="price">¥ <strong>2864</strong> 起</span>
</div>
<div class="type">国内长线</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour2.jpg" alt="马尔代夫双鱼岛Olhuveli4晚6日自助游">
<figcaption><strong class="title"><马尔代夫双鱼岛Olhuveli4晚6日自助游></strong> 上海出发,机+酒包含:早晚餐+快艇</figcaption>
<div>
<em class="sat">满意度 97%</em>
<span class="price">¥ <strong>8039</strong> 起</span>
</div>
<div class="type">出境长线</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour3.jpg" alt="海南双飞5日游">
<figcaption><strong class="title"><海南双飞5日游></strong> 含盐城接送,全程挂牌四星酒店,一价全含,零自费“自费项目”免费送</figcaption>
<div>
<em class="sat">满意度 90%</em>
<span class="price">¥ <strong>2709</strong> 起</span>
</div>
<div class="type">自助旅游</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour4.jpg" alt="富山-大阪-东京8日游">
<figcaption><strong class="title"><富山-大阪-东京8日游></strong> 暑期亲子,2天自由,无导游安排自费项目,全程不强迫购物</figcaption>
<div>
<em class="sat">满意度 97%</em>
<span class="price">¥ <strong>9499</strong> 起</span>
</div>
<div class="type">自助旅游</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour5.jpg" alt="法瑞意德12日游">
<figcaption><strong class="title"><法瑞意德12日游></strong> 4至5星,金色列车,少女峰,部分THE MALL</figcaption>
<div>
<em class="sat">满意度 97%</em>
<span class="price">¥ <strong>9199</strong> 起</span>
</div>
<div class="type">国内短线</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour6.jpg" alt="巴厘岛6日半自助游">
<figcaption><strong class="title"><巴厘岛6日半自助游></strong> 蓝梦出海,独栋别墅,悦榕庄下午茶,纯玩</figcaption>
<div>
<em class="sat">满意度 95%</em>
<span class="price">¥ <strong>6488</strong> 起</span>
</div>
<div class="type">出境长线</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour7.jpg" alt="塞舌尔迪拜9日自助游">
<figcaption><strong class="title"><塞舌尔迪拜9日自助游></strong> 一游两国,4晚塞舌尔,2晚迪拜,香港EK往返</figcaption>
<div>
<em class="sat">满意度 100%</em>
<span class="price">¥ <strong>9669</strong> 起</span>
</div>
<div class="type">游轮观光</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour8.jpg" alt="花样姐姐土耳其9日或10日游">
<figcaption><strong class="title"><花样姐姐土耳其9日或10日游></strong> 最高立减3000!中餐六菜一汤+土耳其当地美食满足您挑剔味蕾</figcaption>
<div>
<em class="sat">满意度 93%</em>
<span class="price">¥ <strong>9999</strong> 起</span>
</div>
<div class="type">出境长线</div>
</figure>
<figure>
<img src="http://www.mamicode.com/img/tour9.jpg" alt="大阪-京都-箱根双飞6日游">
<figcaption><strong class="title"><大阪-京都-箱根双飞6日游></strong> 盐城直飞,不走回头路,境外无自费,超值之旅</figcaption>
<div>
<em class="sat">满意度 100%</em>
<span class="price">¥ <strong>5284</strong> 起</span>
</div>
<div class="type">国内短线</div>
</figure>
</div>
<footer id="footer">
<div class="top">
<div class="block left">
<h2>合作伙伴</h2>
<hr>
<ul>
<li>途牛旅游网</li>
<li>驴妈妈旅游网</li>
<li>携程旅游</li>
<li>中国青年旅行社</li>
</ul>
</div>
<div class="block center">
<h2>旅游FAQ</h2>
<hr>
<ul>
<li>旅游合同签订方式?</li>
<li>儿童价是基于什么制定的?</li>
<li>旅游的线路品质怎么界定的?</li>
<li>单房差是什么?</li>
<li>旅游保险有那些种类?</li>
</ul>
</div>
<div class="block right">
<h2>联系方式</h2>
<hr>
<ul>
<li>微博:weibo.com/ycku</li>
<li>邮件:ycku@ycku.com</li>
<li>地址:江苏盐城无名路123 号</li>
</ul>
</div>
</div>
<div class="bottom">Copyright © YCKU 瓢城旅行社| 苏ICP 备120110119 号| 旅行社经营许可证:L-YC-BK12345</div>
</footer>
</body>
</html>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>项目实战--PC端固定布局</title>
<link rel="stylesheet" href="http://www.mamicode.com/css/basic.css">
<link rel="stylesheet" href="http://www.mamicode.com/css/column.css">
</head>
<body>
<header id="header">
<div class="center">
<h1 class="logo">瓢城旅行社</h1>
<nav class="link">
<h2 class="none">网站导航</h2>
<ul>
<li><a href="http://www.mamicode.com/index.html">首页</a></li>
<li class="active"><a href="http://www.mamicode.com/information.html">旅游资讯</a></li>
<li><a href="http://www.mamicode.com/###">机票订购</a></li>
<li><a href="http://www.mamicode.com/###">风景欣赏</a></li>
<li><a href="http://www.mamicode.com/###">公司简介</a></li>
</ul>
</nav>
</div>
</header>
<div id="headline">
<div class="center">
<hgroup>
<h2>旅游资讯</h2>
<h3>介绍各种最新旅游信息、资讯要闻、景点攻略等</h3>
</hgroup>
</div>
</div>
<div id="container">
<aside class="sidebar">
<div class="sidebox recommend">
<h2>景点推荐</h2>
<div class="tag">
<a href="http://www.mamicode.com/###">曼谷(12)</a>
<a href="http://www.mamicode.com/###">东京(5)</a>
<a href="http://www.mamicode.com/###">西双版纳(8)</a>
<a href="http://www.mamicode.com/###">漓江(16)</a>
<a href="http://www.mamicode.com/###">呼伦贝尔(4)</a>
<a href="http://www.mamicode.com/###">首尔(9)</a>
<a href="http://www.mamicode.com/###">巴厘岛(15)</a>
<a href="http://www.mamicode.com/###">土耳其(22)</a>
<a href="http://www.mamicode.com/###">夏威夷(5)</a>
<a href="http://www.mamicode.com/###">巴厘岛(11)</a>
<a href="http://www.mamicode.com/###">毛里求斯(7)</a>
<a href="http://www.mamicode.com/###">吉普岛(4)</a>
<a href="http://www.mamicode.com/###">希腊(18)</a>
<a href="http://www.mamicode.com/###">法瑞意(8)</a>
<a href="http://www.mamicode.com/###">马尔代夫(9)</a>
<a href="http://www.mamicode.com/###">新西兰(16)</a>
<a href="http://www.mamicode.com/###">埃及(11)</a>
<a href="http://www.mamicode.com/###">迪拜(14)</a>
<a href="http://www.mamicode.com/###">斯里兰卡(7)</a>
<a href="http://www.mamicode.com/###">麦哈顿(3)</a>
<a href="http://www.mamicode.com/###">大阪(15)</a>
</div>
</div>
<div class="sidebox hot">
<h2>热门旅游</h2>
<div class="figure">
<figure>
<img src="http://www.mamicode.com/img/hot1.jpg" alt="曼谷-芭提雅6日游">
<figcaption>曼谷-芭提雅6日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot2.jpg" alt="马尔代夫双鱼6日游">
<figcaption>马尔代夫双鱼6日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot3.jpg" alt="海南双飞5日游">
<figcaption>海南双飞5日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot4.jpg" alt="富山大阪东京8日游">
<figcaption>富山大阪东京8日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot5.jpg" alt="法瑞意德12日游">
<figcaption>法瑞意德12日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot6.jpg" alt="巴厘岛6日半游">
<figcaption>巴厘岛6日半游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot7.jpg" alt="塞舌尔迪拜9日游">
<figcaption>塞舌尔迪拜9日游</figcaption>
</figure>
<figure>
<img src="http://www.mamicode.com/img/hot8.jpg" alt="花样土耳其10日游">
<figcaption>花样土耳其10日游</figcaption>
</figure>
</div>
</div>
<div class="sidebox treasure">
<h2>旅游百宝箱</h2>
<div class="box">
<a href="http://www.mamicode.com/###" class="trea1">天气预报</a>
<a href="http://www.mamicode.com/###" class="trea2">火车票查询</a>
<a href="http://www.mamicode.com/###" class="trea3">航空查询</a>
<a href="http://www.mamicode.com/###" class="trea4">地铁线路查询</a>
</div>
</div>
</aside>
<div class="list">
list
</div>
</div>
<footer id="footer">
<div class="top">
<div class="block left">
<h2>合作伙伴</h2>
<hr>
<ul>
<li>途牛旅游网</li>
<li>驴妈妈旅游网</li>
<li>携程旅游</li>
<li>中国青年旅行社</li>
</ul>
</div>
<div class="block center">
<h2>旅游FAQ</h2>
<hr>
<ul>
<li>旅游合同签订方式?</li>
<li>儿童价是基于什么制定的?</li>
<li>旅游的线路品质怎么界定的?</li>
<li>单房差是什么?</li>
<li>旅游保险有那些种类?</li>
</ul>
</div>
<div class="block right">
<h2>联系方式</h2>
<hr>
<ul>
<li>微博:weibo.com/ycku</li>
<li>邮件:ycku@ycku.com</li>
<li>地址:江苏盐城无名路123 号</li>
</ul>
</div>
</div>
<div class="bottom">Copyright © YCKU 瓢城旅行社| 苏ICP 备120110119 号| 旅行社经营许可证:L-YC-BK12345</div>
</footer>
</body>
</html>
@charset "utf-8";
body,h1,h2,h3,ul,p,figure {
margin: 0;
padding: 0;
}
body {
background-color: #fff;
}
ul {
list-style: outside none none;
}
a {
text-decoration: none;
}
.none {
display: none;
}
#header {
width: 100%;
min-width: 1263px;
height: 70px;
background-color: #333;
box-shadow: 0 1px 10px rgba(0, 0, 0, 0.3);
position: relative;
z-index: 9999;
}
#header .center {
width: 1263px;
height: 70px;
margin: 0 auto;
}
#header .logo {
width: 240px;
height: 70px;
background-image: url(../img/logo.png);
text-indent: -9999px;
float: left;
}
#header .link {
width: 650px;
height: 70px;
line-height: 70px;
color: #eee;
float: right;
}
#header .link li {
width: 120px;
text-align: center;
float: left;
}
#header .link a {
color: #eee;
display: block;
}
#header .link a:hover,
#header .active a {
background-color: #000;
}
#footer {
height: 360px;
background-color: #222;
clear: both;
position: relative;
top: 20px;
}
#footer .top {
width: 1263px;
height: 281px;
margin: 0 auto;
text-align: center;
}
#footer .block {
width: 410px;
height: 280px;
display: inline-block;
text-align: left;
color: #ccc;
vertical-align: top;
}
#footer h2 {
font-size: 24px;
font-weight: normal;
padding: 20px 0 0 20px;
}
#footer hr {
width: 90%;
border: 1px dashed #333;
}
#footer ul {
font-size: 18px;
color: #777;
text-indent: 20px;
line-height: 2;
}
#footer .bottom {
height: 80px;
line-height: 80px;
text-align: center;
color: #777;
background-color: #000;
border-top: 1px solid #444;
}
@charset "utf-8";
#headline {
width: 100%;
min-width: 1263px;
height: 300px;
background: linear-gradient(to right bottom, rgba(0,0,0,0.7), rgba(0,0,0,0)), url(../img/headline.jpg) no-repeat center;
}
#headline .center {
width: 1263px;
height: 300px;
margin: 0 auto;
}
#headline hgroup {
padding: 100px 0 0 50px;
}
#headline h2 {
color: #eee;
font-size: 36px;
letter-spacing: 1px;
}
#headline h3 {
color: #eee;
font-size: 20px;
letter-spacing: 1px;
}
#container {
width: 1263px;
margin: 30px auto;
}
#container .sidebar {
width: 340px;
float: right;
}
#container .sidebox {
border: 1px solid #eee;
margin: 0 0 10px 0;
text-align: center;
}
#container .sidebox h2 {
font-size: 20px;
font-weight: normal;
letter-spacing: 1px;
text-indent: 8px;
height: 40px;
line-height: 40px;
background-color: #fafafa;
color: #666;
text-align: left;
}
#container .tag {
padding: 10px 0;
}
#container .tag a {
display: inline-block;
width: 100px;
height: 35px;
line-height: 35px;
margin: 2px 0;
background-color: #eee;
text-align: left;
text-indent: 8px;
color: #999;
}
#container .tag a:hover {
background-color: #458b00;
color: #fff;
}
#container .figure {
padding: 10px 0;
}
#container figure {
display: inline-block;
padding: 4px;
color: #666;
}
#container .box {
padding: 10px 0;
}
#container .box a {
display: inline-block;
width: 150px;
height: 40px;
line-height: 40px;
margin: 2px 0;
text-align: left;
text-indent: 35px;
color: #999;
}
#container .box a.trea1 {
background: #eee url(../img/trea1.png) no-repeat 10px center;
}
#container .box a.trea2 {
background: #eee url(../img/trea2.png) no-repeat 10px center;
}
#container .box a.trea3 {
background: #eee url(../img/trea3.png) no-repeat 10px center;
}
#container .box a.trea4 {
background: #eee url(../img/trea4.png) no-repeat 10px center;
}
#container .list {
width: 900px;
float: left;
}
@charset "utf-8";
#search {
width: 100%;
min-width: 1263px;
height: 600px;
background: url(../img/search.jpg) no-repeat center;
position: relative;
}
#search .center {
width: 600px;
height: 60px;
background-color: #000;
position: absolute;
top: 50%;
left: 50%;
margin: -30px 0 0 -300px;
opacity: 0.6;
border-radius: 10px;
}
#search .search {
width: 446px;
height: 52px;
background-color: #eee;
position: absolute;
top: 50%;
left: 50%;
margin: -27px 0 0 -296px;
color: #666;
border: 1px solid #666;
border-radius: 10px;
font-size: 24px;
padding: 0 10px;
outline: none;
}
#search .button {
width: 120px;
height: 54px;
background-color: #eee;
position: absolute;
top: 50%;
left: 50%;
margin: -27px 0 0 175px;
color: #666;
border: 1px solid #666;
border-radius: 10px;
font-size: 24px;
outline: none;
cursor: pointer;
font-weight: bold;
}
#tour {
width: 1263px;
height: 1150px;
/*background-color: #ccc;*/
margin: 30px auto;
text-align: center;
}
#tour .center h2 {
font-size: 45px;
letter-spacing: 2px;
color: #666;
margin: 10px 0;
}
#tour .center p {
color: #666;
margin: 10px 0;
}
#tour figure {
border: 1px solid #ddd;
display: inline-block;
padding: 4px;
border-radius: 4px;
margin: 15px 12px;
width: 380px;
text-align: left;
position: relative;
}
#tour figure img {
vertical-align: middle;
}
#tour figcaption {
color: #777;
line-height: 1.5;
letter-spacing: 1px;
font-size: 14px;
padding: 7px 0 5px 0;
}
#tour .title {
color: #333;
font-weight: normal;
}
#tour .sat {
float: right;
font-size: 13px;
color: #999;
font-style: normal;
position: relative;
top: 5px;
right: 5px;
}
#tour .price {
color: #f60;
font-size: 14px;
}
#tour .price strong {
font-size: 20px;
letter-spacing: 1px;
}
#tour .type {
width: 90px;
height: 25px;
line-height: 25px;
font-size: 14px;
text-align: center;
color: #fff;
background-color: #59b200;
position: absolute;
top: 4px;
left: 4px;
}
第31章 项目实战-PC端固定布局7