网页各种设备自适应
🍒本篇是一篇十分优秀的案例,走过路过是千万不能错过~
电脑全屏1920px
手机尺寸375×667
ipad 768×102尺寸 也能轻松应对
🍑🍑🍑 这简直太秀了叭 爱了爱了
代码分析:
第一部分:header部分
正常显示:
缩放后显示:
代码:
htnl部分
<header id="header">
<section class="menu">
menu
<ul>
<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>
</section>
<section class="logo">
<h1><a href="#" title="觉唯设计">觉唯设计
</a></h1>
</section>
<nav class="nav">
<a href="#">文章
</a>
<a href="#">素材
</a>
<a href="#">活动
</a>
<a href="#">素材
</a>
<a href="#">活动
</a>
<a href="#">更多
</a>
</nav>
<a href="#" class="login">登录
</a>
</header>
<section id="banner"></section>
css部分
#header{
position: fixed
;
width: 100%
;
height: 50px
;
background: rgba(53, 50, 50, 0.5
);
display: flex
;
padding:0 50px
;
box-sizing: border-box
;
justify-content: space-between
;
align-items: center
;
}
#header a{
color: #fff
;
}
.logo a{
display: block
;
width: 150px
;
height: 50px
;
background: url(../images/logo.png) no-repeat
;
background-size: cover
;
text-indent: -9999px
;
}
.nav{
display: flex
;
}
.nav a{
line-height: 50px
;
padding: 0 26px
;
}
.menu{ display:none
;
}
#banner{
height: 250px
;
background: url(../images/top-bg.png) no-repeat center top
;
background-size: cover
;
}
第二部分
正常显示:
缩放后显示:
代码:
html部分
<section id="main">
<section class="pic">
<div class="pic-left">
<a href="#"><img src="images/swiper1.jpeg" alt=""></a>
</div>
<div class="pic-right">
<a href="#"><img src="images/1.png" alt=""></a>
<a href="#"><img src="images/2.png" alt=""></a>
</div>
</section>
<section class="photobox">
<figure>
<img src="images/1.jpg" alt="">
<figcaption>
<strong>迷你微型摄影展
</strong>
<div>
<span>2016-12-12
</span><span>作者:tom
</span>
</div>
</figcaption>
</figure>
<figure>
<img src="images/4.jpg" alt="">
<figcaption>
<strong>迷你微型摄影展
</strong>
<div>
<span>2016-12-12
</span><span>作者:tom
</span>
</div>
</figcaption>
</figure>
<figure>
<img src="images/2.jpg" alt="">
<figcaption>
<strong>迷你微型摄影展
</strong>
<div>
<span>2016-12-12
</span><span>作者:tom
</span>
</div>
</figcaption>
</figure>
<figure>
<img src="images/2.jpg" alt="">
<figcaption>
<strong>迷你微型摄影展
</strong>
<div>
<span>2016-12-12
</span><span>作者:tom
</span>
</div>
</figcaption>
</figure>
<figure>
<img src="images/2.jpg" alt="">
<figcaption>
<strong>迷你微型摄影展
</strong>
<div>
<span>2016-12-12
</span><span>作者:tom
</span>
</div>
</figcaption>
</figure>
</section>
</section>
css部分
.pic{
display: flex
;
padding: 0 10px
;
justify-content: space-between
;
flex-wrap: wrap
;
align-content: flex-start
;
margin-top: 10px
;
}
.pic-left{
width: 49%
;
}
.pic-left a{
display: block
;
}
.pic-left a img{
width: 100%
;
}
.pic-right{
width: 49%
;
display: flex
;
justify-content: space-between
;
}
.pic-right a{
display: block
;
width: 49%
;
}
.pic-right a img{
width: 100%
;
}
.photobox{
display: flex
;
justify-content: space-around
;
flex-wrap: wrap
;
align-content: flex-start
;
}
.photobox figure{
width: 24%
;
padding: 5px
;
box-sizing: border-box
;
box-shadow: 3px 3px 10px #999
;
margin-top: 10px
;
}
.photobox figure img{
width: 100%
;
}
@media only screen and (max-width:1024px){
.nav{
display: none
;
}
.menu{
display:block
;
height: 50px
;
line-height: 50px
;
color: #fff
;
cursor: pointer
;
}
.menu ul{
position: absolute
;
left: 0
;
top: 50px
;
width: 100%
;
display: none
;
}
.menu:hover>ul{
display: block
;
}
.menu ul li{
border-top: 1px solid #777777
;
}
.menu ul li a{
display: block
;
height: 50px
;
background: rgba(0,0,0,0.5
);
text-align: center
;
}
.pic{
justify-content: center
;
}
.pic-left{
width: 98%
;
margin-top: 10px
;
}
.pic-right{
width: 98%
;
margin-top: 10px
;
}
.photobox figure{
width: 48%
;
}
}
@media only screen and (max-width:767px){
.photobox figure{
width: 96%
;
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-14977.html