响应式布局

图示1:


图示2:


图示3:

html:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<title>响应式</title>
	<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header id="header">
	<div class="center">
		<h1 class="logo">瓢城旅行社</h1>
		<nav class="link">
			<ul>
				<li><a href="index.html">首页</a></li>
				<li><a href="information.html"><span class="xs-hidden">旅游</span>资讯</a></li>
				<li><a href="ticket.html">机票<span class="xs-hidden">订购</span></a></li>
				<li class="xs-hidden"><a href="scenery.html">风景欣赏</a></li>
				<li class="active"><a href="about.html"><span class="xs-hidden">关于</span>公司</a></li>
			</ul>
		</nav>
	</div>
</header>
</body>
</html>

css:

*{
	margin: 0;
	padding: 0;
}
body{
	background-color: #f5f5f5;
}
#header {
	width: 100%;
	height: 70px;
	background-color: #333;
	box-shadow: 0 1px 10px rgba(0, 0, 0, 0.3);
}
#header .center {
	max-width: 1263px;
	height: 70px;
	margin: 0 auto;
}
/*logo*/
#header .logo {
	width: 30%;
	height: 70px;
	background: url(../img/logo.png) no-repeat left center;
	text-indent: -9999px;
	float: left;
}
#header .center .link{
	width: 55%;
	height: 70px;
	line-height: 70px;
	float: right;
}
#header .center .link li{
	width: 20%;
	text-align: center;
	float: left;
	list-style-type: none;
}
#header .center .link li a{
	display: block;
	text-decoration: none;
	color: #eee;

}
#header .center .link li a:hover,#header .active a{
	background:#000;

}
.sm-visible {
	display: none;
}
/*响应式*/
@media (min-width: 1200px) {
	
}
/*在992 和1199 像素之间的屏幕里,中等屏幕,分辨率低的PC*/
@media (min-width: 992px) and (max-width: 1199px) {

}
/*在768 和991 像素之间的屏幕里,小屏幕,主要是PAD*/
@media (min-width: 768px) and (max-width: 991px) {
	
}
/*在480 和767 像素之间的屏幕里,超小屏幕,主要是手机*/
@media (min-width: 480px) and (max-width: 767px) {
	#header, #header .center, #header .link {
		height: 45px;  /*宽度减小*/
	}
	#header .logo, .sm-hidden,.sidebar,.md-hidden {
		display: none; /*元素消失*/
	}
	#header .center .link {
		width: 100%;
		line-height: 45px;/*调整行高*/
	}
}
/*在小于480 像素的屏幕,微小屏幕,更低分辨率的手机*/
@media (max-width: 479px) {
	#header, #header .center, #header .link {
		height: 45px;
	}
	#header .logo, .xs-hidden, .sm-hidden, .sidebar, .md-hidden  {
		display: none;
	}
	#header .center .link {
		width: 100%;
		line-height: 45px;
	}
	#header .center .link li {
		width: 25%;
	}
	
}

注意点:

1 上下文选择器要一致:上面如果写成#header .center  .link 响应式也要这样写,不可写成#header .link即使是一个意思

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值