CSS3 多媒体查询实例

本文介绍了如何使用CSS3的多媒体查询实现不同屏幕尺寸下的布局变化。例如,在520到699px宽度下为邮箱链接添加图标,700到1000px时显示"Email:"前缀,超过1001px宽度则展示完整邮件地址,且在1151px以上宽度时人名前添加图标。通过data-属性存储信息,实现响应式设计。
摘要由CSDN通过智能技术生成
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			ul {
				list-style-type: none;
			}

			ul li a {
				color: green;
				text-decoration: none;
				padding: 3px; 
				display: block;
			}
		</style>
	</head>
	<body>
		<ul>
		  <li><a data-email="johndoe@example.com" href="mailto:johndoe@example.com">John Doe</a></li>
		  <li><a data-email="marymoe@example.com" href="mailto:marymoe@example.com">Mary Moe</a></li>
		  <li><a data-email="amandapanda@example.com" href="mailto:amandapanda@example.com">Amanda Panda</a></li>
		</ul>
	</body>
</html>

   注意 data-email 属性。在 HTML 中我们可以使用带 data- 前缀的属性来存储信息。

520 到 699px 宽度 - 添加邮箱图标

   当浏览器的宽度在 520 到 699px, 邮箱链接前添加邮件图标:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			ul {
				list-style-type: none;
			}

			ul li a {
				color: green;
				text-decoration: none;
				padding: 3px; 
				display: block;
			}
			
			@media screen and (max-width: 699px) and (min-width:520px) {
				ul li a{
					padding-left: 30px;
					background:url(img_tree.png) left center no-repeat;
				}
			}
		</style>
	</head>
	<body>
		<h1>重置浏览器窗口,查看效果!</h1>
		
		<ul>
		  <li><a data-email="johndoe@example.com" href="mailto:johndoe@example.com">John Doe</a></li>
		  <li><a data-email="marymoe@example.com" href="mailto:marymoe@example.com">Mary Moe</a
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值