@media 讲解

12 篇文章 0 订阅


一、媒体

all 所有媒体
braille 盲文触觉设备
embossed 盲文打印机
print 手持设备
projection 打印预览
screen 彩屏设备
speech '听觉'类似的媒体类型
tty 不适用像素的设备
tv  电视


Demo:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			#box{
				width:100px;
				height:100px;
				background-color:red;
			}
			@media embossed{
				/*盲文打印机是绿色*/
				#box{
					background-color:green;
				}
			}
			@media tv{
				/*在tv上是粉色*/
				#box{
					background-color:pink;
				}
			}
			@media all{
				/*在所有媒体上是红色*/
				#box{
					background-color:red;
				}
			}
		</style>
	</head>
	<body>
		<div id="box"></div>
	</body>
</html>

二、关键字

and : 连接

        @media all and (min-width:1000px)

only : 某种特定的媒体类型 

        @media only screen

not : 关键是用来排除某种特定的媒体类型

        @media not tv   


/*@media only 设备类型 只有在某种特定的设备上 识别*/
/*
@media only screen{
    仅仅在彩屏设备下识别
    #demo{
        background:blue;
    }
}
 

*/
/*当屏幕大于等于500像素的时候*/
/*
@media all and (min-width:500px){
    #demo{
        background:green;
    }
}
*/
/*当屏幕小于等于500像素的时候*/

@media all and (max-width:900px){
    #demo{
        background:yellow;
    }
}


三、横屏、竖屏

提示:这只是初步的监测,但不是最好的,后期有讲解最新的

/*竖屏*/
@media (orientation:portrait){
    div{
        background:yellow;
    }
}

/*横屏*/
@media (orientation:landscape){
    div{
        background:blue;
    }
}


四、css 引入

第一种

<link rel="stylesheet" type="text/css" href="a1.css" media="all and (min-width:400px)" />
<link rel="stylesheet" type="text/css" href="a2.css" media="all and (min-width:600px)" />

第二种

<style type="text/css">
@import url(a1.css) (min-width:400px);
@import url(a2.css) (min-width:600px);

</style>




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值