移动端布局之流式布局2
案例:京东移动端首页
二倍精灵图的做法
-
在firework中里面把精灵图等比例缩放为原来的一半(也可以在ps中)
-
在ps中用选区将所选区域选中,打开工具栏中的“窗口=>信息”会出现鼠标的x和y值,记录下来
(根据大小 测量坐标)
-
注意代码里面的background-size也要写:精灵图原来宽度的一半
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<title>Title</title>
<!--引入我们的css初始化文件-->
<link rel="stylesheet" href="css/normalize.css">
<!--引入我们首页的css-->
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<header class="app">
<ul>
<li>
<img src="images/close.png" alt="">
</li>
<li>
<img src="images/logo.png" alt="">
</li>
<li>打开京东APP,实惠又轻松</li>
<li>立即打开</li>
</ul>
</header>
<!--搜索-->
<div class="search-wrap">
<div class="search-btn"></div>
<div class="search">
<div class="jd-icon"></div>
<div class="sou"></div>
</div>
<div class="search-login">登录</div>
</div>
</body>
</html>
index.css
body{
width: 100%;
max-width: 1080px;
min-width: 320px;
margin: 0 auto;
font-size: 14px;
color: #666;
font-family: -apple-system,Helvetica,sans-serif; /*苹果手机文字,安卓手机默认字体*/
line-height: 1.5; /*字体大小的1.5倍*/
background-color: #ccc;
}
.app{
height: 45px;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
.app ul li{
float: left;
height: 45px;
background-color: #333;
color: #fff;
text-align: center; /*图片水平居中*/
line-height: 45px; /*图片垂直居中*/
}
.app ul li:nth-child(1){
width: 8%;
}
.app ul li:nth-child(1) img{
width: 10px;
}
.app ul li:nth-child(2){
width: 10%;
}
.app ul li:nth-child(2) img{
width: 30px;
/*由于图片默认和文字的基线对齐,因此要将图片和文字居中对齐(适用于行内块元素)*/
vertical-align: middle;
}
.app ul li:nth-child(3){
width: 57%;
}
.app ul li:nth-child(4){
width: 25%;
background-color: #f53516;
}
.search-wrap{
height: 44px;
position: relative;
/*外边距合并,解决方法是给父级添加overflow:hidden*/
overflow: hidden;
}
.search-btn{
position: absolute;
width: 40px;
height: 44px;
top: 0;
left: 0;
}
.search-btn::before{
content: "";
display: block;
width: 20px;
height: 18px;
background: url("../images/s-btn.png") no-repeat;
background-size: 20px 18px;
margin: 14px 0 0 15px;
}
.search-login{
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 44px;
line-height: 44px;
color: #fff;
}
.search{
height: 30px;
margin: 0 50px;
border-radius: 15px;
background-color: #fff;
/*外边距合并,解决方法是给父级添加overflow:hidden*/
margin-top: 7px;
position: relative;
}
.jd-icon{
width: 20px;
height: 15px;
position: absolute;
top: 8px;
left: 13px;
background: url("../images/jd.png") no-repeat;
background-size: 20px 15px;
}
/*JD图标后的小竖杠*/
.jd-icon::after{
content: "";
position: absolute;
right: -8px;
top: 0;
display: block;
width: 1px;
height: 15px;
background-color: #ccc;
}
.sou{
width: 18px;
height: 15px;
position: absolute;
top: 8px;
left: 50px;
background: url(../images/jd-sprites.png) no-repeat -80px 0;
background-size: 200px;
}
背景渐变
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<title>Title</title>
<!--引入我们的css初始化文件-->
<link rel="stylesheet" href="css/normalize.css">
<!--引入我们首页的css-->
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<header class="app">
<ul>
<li>
<img src="images/close.png" alt="">
</li>
<li>
<img src="images/logo.png" alt="">
</li>
<li>打开京东APP,实惠又轻松</li>
<li>立即打开</li>
</ul>
</header>
<!--搜索-->
<div class="search-wrap">
<div class="search-btn"></div>
<div class="search">
<div class="jd-icon"></div>
<div class="sou"></div>
</div>
<div class="search-login">登录</div>
</div>
<!--背景渐变-->
<div class="slider-bg"></div>
</body>
</html>
index.css
body{
width: 100%;
max-width: 1080px;
min-width: 320px;
margin: 0 auto;
font-size: 14px;
color: #666;
font-family: -apple-system,Helvetica,sans-serif; /*苹果手机文字,安卓手机默认字体*/
line-height: 1.5; /*字体大小的1.5倍*/
background-color: #ccc;
}
.app{
height: 45px;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
.app ul li{
float: left;
height: 45px;
background-color: #333;
color: #fff;
text-align: center; /*图片水平居中*/
line-height: 45px; /*图片垂直居中*/
}
.app ul li:nth-child(1){
width: 8%;
}
.app ul li:nth-child(1) img{
width: 10px;
}
.app ul li:nth-child(2){
width: 10%;
}
.app ul li:nth-child(2) img{
width: 30px;
/*由于图片默认和文字的基线对齐,因此要将图片和文字居中对齐(适用于行内块元素)*/
vertical-align: middle;
}
.app ul li:nth-child(3){
width: 57%;
}
.app ul li:nth-child(4){
width: 25%;
background-color: #f53516;
}
.search-wrap{
height: 44px;
position: relative;
/*外边距合并,解决方法是给父级添加overflow:hidden*/
overflow: hidden;
}
.search-btn{
position: absolute;
width: 40px;
height: 44px;
top: 0;
left: 0;
}
.search-btn::before{
content: "";
display: block;
width: 20px;
height: 18px;
background: url("../images/s-btn.png") no-repeat;
background-size: 20px 18px;
margin: 14px 0 0 15px;
}
.search-login{
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 44px;
line-height: 44px;
color: #fff;
}
.search{
height: 30px;
margin: 0 50px;
border-radius: 15px;
background-color: #fff;
/*外边距合并,解决方法是给父级添加overflow:hidden*/
margin-top: 7px;
position: relative;
}
.jd-icon{
width: 20px;
height: 15px;
position: absolute;
top: 8px;
left: 13px;
background: url("../images/jd.png") no-repeat;
background-size: 20px 15px;
}
/*JD图标后的小竖杠*/
.jd-icon::after{
content: "";
position: absolute;
right: -8px;
top: 0;
display: block;
width: 1px;
height: 15px;
background-color: #ccc;
}
.sou{
width: 18px;
height: 15px;
position: absolute;
top: 8px;
left: 50px;
background: url(../images/jd-sprites.png) no-repeat -80px 0;
background-size: 200px;
}
.slider-bg{
position: absolute;
top: 0;
width: 150%;
height: 200px;
left: -25%;
z-index: -1;
background: linear-gradient(0deg,#f1503b,#c82519 50%);
border-bottom-left-radius: 100%;
border-bottom-right-radius: 100%;
}
焦点图与折扣日制作
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<title>Title</title>
<!--引入我们的css初始化文件-->
<link rel="stylesheet" href="css/normalize.css">
<!--引入我们首页的css-->
<link rel="stylesheet" href="css/index.css">
</head>
<body>
<header class="app">
<ul>
<li>
<img src="images/close.png" alt="">
</li>
<li>
<img src="images/logo.png" alt="">
</li>
<li>打开京东APP,实惠又轻松</li>
<li>立即打开</li>
</ul>
</header>
<!--搜索-->
<div class="search-wrap">
<div class="search-btn"></div>
<div class="search">
<div class="jd-icon"></div>
<div class="sou"></div>
</div>
<div class="search-login">登录</div>
</div>
<!--背景渐变-->
<div class="slider-bg"></div>
<!--主体内容部分-->
<div class="main-content">
<!--滑动图-->
<div class="slider">
<img src="upload/banner.jpeg" alt="">
</div>
<!--折扣价-->
<div class="brand">
<div>
<a href="#">
<img src="upload/discount-left.png" alt="">
</a>
</div>
<div>
<a href="#">
<img src="upload/discount-middle.png" alt="">
</a>
</div>
<div>
<a href="#">
<img src="upload/discount-right.png" alt="">
</a>
</div>
</div>
</div>
</body>
</html>
index.css
body{
width: 100%;
max-width: 1080px;
min-width: 320px;
margin: 0 auto;
font-size: 14px;
color: #666;
font-family: -apple-system,Helvetica,sans-serif; /*苹果手机文字,安卓手机默认字体*/
line-height: 1.5; /*字体大小的1.5倍*/
background-color: #ccc;
}
.app{
height: 45px;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
.app ul li{
float: left;
height: 45px;
background-color: #333;
color: #fff;
text-align: center; /*图片水平居中*/
line-height: 45px; /*图片垂直居中*/
}
.app ul li:nth-child(1){
width: 8%;
}
.app ul li:nth-child(1) img{
width: 10px;
}
.app ul li:nth-child(2){
width: 10%;
}
.app ul li:nth-child(2) img{
width: 30px;
/*由于图片默认和文字的基线对齐,因此要将图片和文字居中对齐(适用于行内块元素)*/
vertical-align: middle;
}
.app ul li:nth-child(3){
width: 57%;
}
.app ul li:nth-child(4){
width: 25%;
background-color: #f53516;
}
.search-wrap{
height: 44px;
position: relative;
/*外边距合并,解决方法是给父级添加overflow:hidden*/
overflow: hidden;
width: 100%;
/*position: fixed;*/
/*max-width: 640px;*/
/*min-width: 320px;*/
}
.search-btn{
position: absolute;
width: 40px;
height: 44px;
top: 0;
left: 0;
}
.search-btn::before{
content: "";
display: block;
width: 20px;
height: 18px;
background: url("../images/s-btn.png") no-repeat;
background-size: 20px 18px;
margin: 14px 0 0 15px;
}
.search-login{
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 44px;
line-height: 44px;
color: #fff;
}
.search{
height: 30px;
margin: 0 50px;
border-radius: 15px;
background-color: #fff;
/*外边距合并,解决方法是给父级添加overflow:hidden*/
margin-top: 7px;
position: relative;
}
.jd-icon{
width: 20px;
height: 15px;
position: absolute;
top: 8px;
left: 13px;
background: url("../images/jd.png") no-repeat;
background-size: 20px 15px;
}
/*JD图标后的小竖杠*/
.jd-icon::after{
content: "";
position: absolute;
right: -8px;
top: 0;
display: block;
width: 1px;
height: 15px;
background-color: #ccc;
}
.sou{
width: 18px;
height: 15px;
position: absolute;
top: 8px;
left: 50px;
background: url(../images/jd-sprites.png) no-repeat -80px 0;
background-size: 200px;
}
.slider-bg{
position: absolute;
top: 0;
width: 150%;
height: 200px;
left: -25%;
z-index: -1;
background: linear-gradient(0deg,#f1503b,#c82519 50%);
border-bottom-left-radius: 100%;
border-bottom-right-radius: 100%;
}
.slider{
margin: 0 13px;
overflow: hidden;
}
.slider img{
width: 100%;
border-radius: 10px;
}
/*品牌折扣日*/
.brand{
border-radius: 10px 10px 0 0;
overflow: hidden;
}
.brand div{
width: 33.33%;
float: left;
}
.main-content img{
/*去除图片底下的空白缝隙*/
vertical-align: top;
}
.brand a img{
width: 100%;
height: 192.02px;
}