点击查看运行
html部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0 ,initial-scale=1.0" id="view"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>rem适配练习</title>
<link rel="stylesheet" href="./index.css">
<script>
(function(doc,win,designWidth){
var html=doc.documentElement;
function refreshRem(){
var clientWidth=html.clientWidth;
if(clientWidth>=designWidth){
html.style.fontSize="100px";//给宽度一个最大值,如果设备的宽度已经超过设计稿的尺寸了,统一按一个值去算。
}else{
// html.style.fontSize=16*clientWidth/375+'px';//以iphone6字体大小为16px为基准
html.style.fontSize=100*(clientWidth/designWidth)+'px';//
}
};
doc.addEventListener('DOMContentLoaded',refreshRem);//dom加载完执行事件
})(document,window,750);
</script>
</head>
<body>
<header id="header">
<a href="#">北京市</a>
<div>
<input type="text" placeholder="输入店铺,商品等">
</div>
<a href="#">我的</a>
</header>
<section class="banner">
<a href="#"><img src="images/banner.jpg" alt=""></a>
</section>
<nav class="nav">
<ul>
<li>
<a href="#">
<img src="images/circle_01.png" alt="">
<span>餐饮住宿</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_02.png" alt="">
<span>汽车美容</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_03.png" alt="">
<span>生活服务</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_04.png" alt="">
<span>休闲娱乐</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_05.png" alt="">
<span>教育培训</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_06.png" alt="">
<span>家居建材</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_07.png" alt="">
<span>酒水饮料</span>
</a>
</li>
<li>
<a href="#">
<img src="images/circle_08.png" alt="">
<span>婚纱婚庆</span>
</a>
</li>
</ul>
</nav>
<section id="ad1" class="clearfix">
<a href="#"><img src="images/img_01.jpg" alt=""></a>
<a href="#"><img src="images/img_02.jpg" alt=""></a>
<a href="#"><img src="images/img_03.jpg" alt=""></a>
</section>
<section id="ad2">
<a href="#"><img src="images/img_04.jpg" alt=""></a>
</section>
<section id="list">
<h3><span>综合推荐</span></h3>
<article>
<a href="#">
<div class="img">
<img src="images/img_05.jpg" alt="">
</div>
<div class="text">
<h4>悠悠奶茶</h4>
<p>销售各类散茶、品牌茶叶、茶具。全品一展示茶叶茶具批牌茶叶、茶具。全品一展示茶叶茶具发商</p>
<div>
剩余领取<strong>0</strong>份
<span class="discount">8.0折</span>
<span class="red">幸运红包</span>
</div>
</div>
</a>
</article>
<article>
<a href="#">
<div class="img">
<img src="images/img_05.jpg" alt="">
</div>
<div class="text">
<h4>悠悠奶茶</h4>
<p>销售各类散茶、品牌茶叶、茶具。全品一展示茶叶茶具批牌茶叶、茶具。全品一展示茶叶茶具发商</p>
<div>
剩余领取<strong>0</strong>份
<span class="discount">8.0折</span>
<span class="red">幸运红包</span>
</div>
</div>
</a>
</article>
<article>
<a href="#">
<div class="img">
<img src="images/img_05.jpg" alt="">
</div>
<div class="text">
<h4>悠悠奶茶</h4>
<p>销售各类散茶、品牌茶叶、茶具。全品一展示茶叶茶具批牌茶叶、茶具。全品一展示茶叶茶具发商</p>
<div>
剩余领取<strong>0</strong>份
<span class="discount">8.0折</span>
<span class="red">幸运红包</span>
</div>
</div>
</a>
</article>
<article>
<a href="#">
<div class="img">
<img src="images/img_05.jpg" alt="">
</div>
<div class="text">
<h4>悠悠奶茶</h4>
<p>销售各类散茶、品牌茶叶、茶具。全品一展示茶叶茶具批牌茶叶、茶具。全品一展示茶叶茶具发商</p>
<div>
剩余领取<strong>0</strong>份
<span class="discount">8.0折</span>
<span class="red">幸运红包</span>
</div>
</div>
</a>
</article>
</section>
</body>
</html>
css部分:
/* 样式重置 */
body {
font-family: helvetica;
margin: 0 auto;
/* max-width: 750px; */
}
@media screen and (min-width: 750px){
body{
width: 750px;
}
}
body * {
-webkit-user-select: none;
-webkit-touch-callout: none;
-webkit-text-size-adjust: 100%;
}
a,button,input {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
button,input {
-webkit-appearance: none;
border-radius: 0;
}
a {
text-decoration: none;
}
input {
outline: none;
vertical-align: middle;
padding: 0;
}
ul{
margin: 0;
padding: 0;
list-style: none;
}
img{
vertical-align: middle;
}
h3,h4,p{
margin: 0;
}
.left {
float: left;
}
.right {
float: right;
}
.clearfix:after {
content: '';
display: block;
clear: both;
}
*{
margin:0;
padding:0;
list-style: none;
text-decoration: none;
}
/* heaader */
#header{
display: flex;
align-items: center;
height:50px;
line-height: 50px;
background-color:#d22147;
font-size:14px;
color:#fff;
}
#header a{
color:#fff;
}
#header a:nth-of-type(1){
text-align: center;
flex:0 0 80px;
}
#header a:nth-of-type(1):after{
content: "";
display: inline-block;
width: 12.5px;
height:7px;
background: url(images/ico_01.png) no-repeat center/cover ;
/* background-size: cover; */
margin-left: 4px;
}
#header div{
flex:1;
}
#header div input{
text-indent: 34px;
/* padding-left:34px; */
width:100%;
height:32px;
border-radius: 8px;
border:none;
color:#e2c2c9;
background: #ae3e56 url(images/ico_02.png) no-repeat 8px 5px/21px 22px;
}
#header a:nth-of-type(2){
text-align: center;
flex:0 0 69px;
}
#header a:nth-of-type(2):before{
content: "";
display: inline-block;
width: 13px;
height:13px;
background: url(images/ico_03.png) no-repeat center/cover ;
/* background-size: cover; */
margin-right: 5px;
}
/* banner */
.banner{
text-align: center;
}
.banner a img{
width:7.5rem;
/* width:100%; */
}
.nav {
font-size: 0px;
}
.nav ul{
background-color:#f2f0f0;
}
.nav li{
width:25%;
display:inline-block;
text-align: center;
margin:0.2rem 0;
}
nav li a{
font-size:0.28rem;
color:#525252;
}
nav li img{
display:block;
margin:0 auto 0.1rem auto;
width:0.75rem;
height:0.75rem;
}
/* ad1 */
#ad1 a{
float:left;
/* display: inline-block; */
}
#ad1 a img{
width:2.5rem;
height:2.5rem;
}
/* ad2 */
#ad2{
background-color: #f2f0f0;
padding: 0.3rem 0;
}
#ad2 img{
width:100%;
}
#list h3{
font-size: 16px;
color:#131313;
height:40px;
line-height: 40px;
padding-left:10px;
font-weight:normal;
/* border-bottom:1px solid #d2d2d4; */
position: relative;
}
/* 解决1px的问题 */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
#list h3:after {
content: " ";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 1px;
border-bottom: 1px solid #c1c0c5;
color: #c1c0c5;
transform-origin: 0 0;
transform: scaleY(0.5);
}
}
#list h3::before{
content:"";
display:inline-block;
width:0.08rem;
height:0.32rem;
background-color:#cc0530;
border-radius:0.05rem;
margin-right:0.2rem;
vertical-align: middle;
}
#list h3 span{
vertical-align: middle;
}
#list article{
position: relative;
/* border-bottom:1px solid #c1c0c5; */
}
@media screen and (-webkit-min-device-pixel-ratio: 2) {
#list article:after {
content: " ";
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 1px;
border-bottom: 1px solid #c1c0c5;
color: #c1c0c5;
transform-origin: 0 0;
transform: scaleY(0.5);
}
}
#list article a{
padding:0.2rem;
display:flex;
}
#list article .img{
flex :0 0 auto;
padding-right:0.3rem;
}
#list article .img img{
width:2.14rem;
height:1.94rem;
}
#list article .text{
flex:2 2 auto;
}
#list article .text h4{
font-size: 0.28rem;
color:#181818;
line-height: 0.6rem;
margin-bottom:0.05rem;
}
#list article .text p{
font-size: 0.24rem;
color:#979797;
line-height: 0.36rem;
margin-bottom:0.19rem;
/*...表示 */
display:-webkit-box;
-webkit-line-clamp:2;/*设置文本显示行数*/
-webkit-box-orient:vertical;
overflow: hidden;
}
#list article .text div{
height:0.34rem;
font-size: 0.24rem;
line-height: 0.34rem;
color:#525252;
}
#list article .text div strong{
color:#cc0530;
margin:0 0.09rem;
}
.text .discount{
display:inline-block;
width:0.84rem;
height:0.33rem;
color:#fff;
background:url(images/ico_04.gif) no-repeat ;
background-size: cover;
padding-left:0.15rem;
margin-left: 0.15rem;
box-sizing: border-box;
}
.text .red{
float:right;
background:url(images/ico_05.png) no-repeat left center ;
background-size:0.24rem 0.22rem;
padding-left:0.28rem;
}