简单页面导航栏的媒体查询
媒体查询很简单的!!!
代码如下
@media screen {
}
例子:
先写一个导航栏
html代码如下
<div class="box">
<div class="nav">
<a href="#">Home</a>
<a href="#">首页</a>
<a href="#">时间</a>
<a href="#">尾页</a>
<a href="#">年限</a>
</div>
</div>
css代码如下
.box {
width: 100%;
height: 30px;
background: red;
}
.nav {
margin: 0 auto;
width: 1200px;
/* height: 30px; */
background: green;
/* overflow: hidden; */
}
.nav a:first-child {
font-size: 20px;
margin-right: 20px;
}
.nav a {
color: white;
display: inline-block;
width: 150px;
height: 30px;
text-align: center;
line-height: 30px;
text-decoration: none;
}
.nav a:not(:first-child):hover {
color: black;
background: yellow;
}
然后你就得到这样图片
重点来了
媒体查询样式
/* 媒体查询 */
@media screen and (max-width:600px) {
.nav {
width: 100%;
}
.nav a {
float: none;
width: 100%;
text-align: left;
padding-left: 20px;
}
}
效果如下