首页 > 代码库 > 第32 章项目实战-移动端流体布局3
第32 章项目实战-移动端流体布局3
第32 章项目实战-移动端流体布局[3]
学习要点:
1.搜索部分
2.旅游部分
3.媒体查询
本章主要开始如果通过第一个PC 端项目进行重构,设计成移动端可访问的页面,这个
项目采用的是流体布局。
一.搜索部分
搜索部分包含三个内容,背景区块、文本框和按钮。
//HTML 部分
<div id="search">
<input type="text" class="search" placeholder="请输入旅游景点或城市">
<button class="button">搜索</button>
</div>
//CSS 部分
#search {
max-width: 6.4rem;
height: .33rem;
background-color: #ddd;
margin: 0 auto;
position: relative;
padding: .03rem 0 0 0;
}
#search .search {
display: block;
outline: none;
width: 95%;
font-size: .14rem;
border-radius: .04rem;
background-color: #fff;
border: none;
height: .27rem;
padding: 0 .05rem;
margin: 0 auto;
}
#search .button {
display: block;
background-color: #eee;
outline: none;
cursor: pointer;
color: #666;
width: .5rem;
height: .27rem;
border: none;
border-top-right-radius: .04rem;
border-bottom-right-radius: .04rem;
position: absolute;
font-size: .12rem;
top: .03rem;
right: 1%;
}
//布局忽略边框计算
div {
box-sizing: border-box;
}
二.旅游部分
这里,我们首先设计一个标题,具体图片部分放到后面一节课。
//HTML 部分
<div id="tour">
<hgroup>
<h2>热门旅游</h2>
<h3>最新的各种热门旅游资讯的推荐!</h3>
</hgroup>
</div>
//CSS 部分
#tour {
max-width: 6.4rem;
margin: .1rem auto 0 auto;
}
#tour h2 {
text-align: center;
color: #666;
font-size: .26rem;
}
#tour h3 {
text-align: center;
font-weight: normal;
color: #666;
margin: 0.05rem 0 0.1rem 0;
font-size: .16rem;
}
三.媒体查询
媒体查询,这里我们不去详细去讲解,这个放到后面响应式章节讲解,这里简单使用即
可。
/*媒体查询,大于480 小于640*/
@media (min-width: 480px) and (max-width: 640px) {
#tour h2 {
font-size: .26rem;
}
#tour h3 {
font-size: .16rem;
}
#footer {
font-size: .14rem;
}
}
/*媒体查询,小于480*/
@media (max-width: 480px) {
#tour h2 {
font-size: .18rem;
}
#tour h3 {
font-size: .14rem;
}
#footer {
font-size: .12rem;
}
}
代码:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
<title>瓢城旅行社-移动端</title>
<link rel="stylesheet" href="http://www.mamicode.com/css/style.css">
</head>
<body>
<header id="header">
<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/ticket.html">票务</a></li>
<li><a href="http://www.mamicode.com/about.html">关于</a></li>
</ul>
</nav>
</header>
<div id="adver">
<img src="http://www.mamicode.com/img/adver.png" >
</div>
<div id="search">
<input type="text" class="search" placeholder="请输入旅游景点或城市">
<button class="button">搜索</button>
</div>
<div id="tour">
<hgroup>
<h2>热门旅游</h2>
<h3>最新的各种热门旅游资讯的推荐!</h3>
</hgroup>
</div>
<footer id="footer">
<div class="top">
客户端 | 触屏版 | 电脑版
</div>
<div class="bottom">
Copyright © YCKU 瓢城旅行社 | 苏ICP备120110119号
</div>
</footer>
</body>
</html>
@charset "utf-8";
html {
font-size: 625%;
}
body,h1,h2,h3,p,ul,ol,form,fieldset,figure {
margin: 0;
padding: 0;
}
body {
background-color: #fff;
font-family: "Helvetica Neue", Helvetica, Arial, "Microsoft Yahei UI", "Microsoft YaHei", SimHei, "\5B8B\4F53", simsun, sans-serif;
font-size: .16rem;
}
ul,ol {
list-style: outside none none;
}
a {
text-decoration: none;
}
img {
display: block;
max-width: 100%;
}
div {
box-sizing: border-box;
}
.none {
display: none;
}
#header {
width: 100%;
height: .45rem;
background-color: #333;
font-size: 0.16rem;
}
#header .link {
height: .45rem;
line-height: .45rem;
color: #eee;
}
#header .link li {
width: 25%;
text-align: center;
float: left;
}
#header .link a {
color: #eee;
display: block;
}
#header .link a:hover,
#header .active a {
background-color: #000;
}
#adver {
max-width: 6.4rem;
margin: 0 auto;
}
#footer {
max-width: 6.4rem;
background-color: #222;
color: #777;
margin: 0 auto;
text-align: center;
padding: .1rem 0;
font-size: .16rem;
}
#footer .top {
padding: 0 0 .05rem 0;
}
#search {
max-width: 6.4rem;
height: .33rem;
margin: 0 auto;
background-color: #ddd;
padding: .03rem 0 0 0;
position: relative;
}
#search .search {
width: 95%;
height: .27rem;
border-radius: .04rem;
border: none;
outline: none;
background-color: #fff;
display: block;
margin: 0 auto;
font-size: .14rem;
padding: 0 .05rem;
}
#search .button {
display: block;
outline: none;
width: .5rem;
height: .27rem;
color: #666;
border: none;
background-color: #eee;
border-top-right-radius: .04rem;
border-bottom-right-radius: .04rem;
font-size: .14rem;
position: absolute;
top: .03rem;
right: 1%;
}
#tour {
max-width: 6.4rem;
margin: .1rem auto 0 auto;
}
#tour h2 {
text-align: center;
color: #666;
font-size: .26rem;
}
#tour h3 {
text-align: center;
color: #666;
font-weight: normal;
font-size: .16rem;
margin: .05rem 0 .1rem 0;
}
/*媒体查询,大于480px小于640px*/
@media (min-width: 480px) and (max-width: 640px) {
#tour h2 {
font-size: .26rem;
}
#tour h3 {
font-size: .16rem;
}
#footer {
font-size: .16rem;
}
}
/*媒体查询,小于480px*/
@media (max-width: 480px) {
#tour h2 {
font-size: .20rem;
}
#tour h3 {
font-size: .14rem;
}
#footer {
font-size: .12rem;
}
}
第32 章项目实战-移动端流体布局3