Media query of CSS

本文介绍如何使用CSS媒体查询来根据不同设备类型(如屏幕、打印等)调整网页样式。通过示例展示如何设置不同屏幕宽度下的背景颜色,实现响应式设计。

When we use a css file ,we have a link at the head of html:

<link type="text/css"  href="css/main.css" rel="stylesheet"></link>

 

then we can define the style of css  in main.css and use it.ya,here we use the default media value: media = "all".that means,the link is the same when we add media="all" in the link:

<link type="text/css" media="all" href="css/main.css" rel="stylesheet"></link>

 


here are media types we often refer is:

      aural,print,screen,braille,handheld,tty,tv,projection

U can have a try ,in the pc computer ,if we use media="screen" in the <link>,the css will be work,if you set the media ='print' or someelse,the main.css file will invalid.So when use the html in different media types , we can change the css style by not change anything.because we can define a css file for one type.

     And we also can use syntax like this:

   @media screen and width:1440 px {

          body { background:red }

  }

   @media screen and width:240 px {

          body { background:blue }

  }
  so when we open the html , in the pc, the backgroud will be red,but if we open it in ophone screen which width is 240px,the backgroud will be blue;

 

it is a good helper indeed.

at last ,give the link of offical documents, you can find detailed info there,good luck:

http://www.w3.org/TR/2009/CR-css3-mediaqueries-20090423/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值