您的位置:首页 > Web前端 > CSS

css语法规则屏幕自适应及条目应用优先权

2015-04-05 23:41 344 查看
1.

!important 提升指定样式条目的应用优先权。

div {
color: #f00 !important;
color: #000;
}
在上述代码中,IE6及以下浏览器div的文本颜色为#000,!important并没有覆盖后面的规则;其它浏览器下div的文本颜色为#f00

2.可以让屏幕自适应的方法:

/* 样式代码导入 样式文件 */

第一种方式:

<link media="screen and (width:800px)" rel="stylesheet" href="style/css800.css">
<link media="screen and (width:1280px)" rel="stylesheet" href="style/css1280.css">
<link media="screen and (width:1440px)" rel="stylesheet" href="style/css1440.css">

第二种方式:

<style>

@import url(style/css800.css) screen and (min-width:800px);
@import url(style/css1280.css) screen and (min-width:1280px);
@import url(style/css1440.css) screen and (min-width:1440px);

</style>

如下为css800.css的代码

1 #container{
2     width:760px;
3     height:300px;
4     border:1px solid red;
5     background-color:red;
6 }


如下为css1280.css的代码

#container{
width:1004px;
height:300px;
border:1px solid red;
background-color:red;
}


如下为css1440.css的代码

1 #container{
2     width:1320px;
3     height:300px;
4     border:1px solid red;
5     background-color:red;
6 }


第三种方式:

*{
margin:0;
border:0;
padding:0;
}
#container{
width:1240px;
height:300px;
background-color:red;
margin:0 auto;
}

/* 当屏幕的分辨率宽度小于等于1260px时,执行如下样式代码 */
@media (max-width:1260px) {
#container{
width:930px;
background-color:green;
}
}

/* 当屏幕的分辨率宽度小于等于800px时,执行如下样式代码 */
@media (max-width:800px) {
#container{
width:760px;
background-color:blue;
}
}

</style>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: