面试时可能被问到的CSS问题有哪些-创新互联

这篇文章主要介绍面试时可能被问到的CSS问题有哪些,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联建站专注于企业成都全网营销推广、网站重做改版、凉城网站定制设计、自适应品牌网站建设、成都h5网站建设商城网站定制开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为凉城等各大城市提供网站开发制作服务。

问:

CSS选择符有哪些?哪些属性可以继承?优先级?内联和important哪个优先级高?

选择符

1通配选择符(*)表示页面内所有元素的样式*{font-size:12px;margin:0;padding:0;}
2类型选择符(body、div、p、span等)网页中已有的标签类型作为名称的选择符div{width:10px;height:10px;}
3群组选择符(,)对一组对象同时进行相同的样式指派a:link,a:visited{color:#fff;}
4层次选择符(空格)包含选择符对某对象中的子对象进行样式指派#header top{width:100px;}
5id选择符(#)id选择符具有性,在页面中不能重复使用#header{width:300px;}
6class选择符(.)可以在页面中重复使用.title{width:300px;}
7IEhack选择符(_、*、\0、\9\0;)兼容不同的浏览器.title{_width:50px;*height:30px;}

可继承的属性

代码如下:


azimuth, border-collapse, border-spacing,
caption-side, color, cursor, direction, elevation,
empty-cells, font-family, font-size, font-style,
font-variant, font-weight, font, letter-spacing,
line-height, list-style-image, list-style-position,
list-style-type, list-style, orphans, pitch-range,
pitch, quotes, richness, speak-header, speaknumeral,
speak-punctuation, speak, speechrate,
stress, text-align, text-indent, texttransform,
visibility, voice-family, volume, whitespace,
widows, word-spacing


优先级的四大原则

原则1:继承没指定的牛B

demo1:

代码如下:


<style type="text/css">
*{font-size:20px}
.class3{ font-size: 12px; }
</style> </p> <p><span class="class3">我是多大字号?</span> <!-- 运行结果:.class3{ font-size: 12px; }-->


demo2:

代码如下:


<style type="text/css">
#id1 #id2{font-size:20px}
.class3{font-size:12px}
</style> </p> <p><div id="id1" class="class1">
<p id="id2" class="class2"> <span id="id3" class="class3">我是多大字号?</span> </p>
</div> <!--运行结果:.class3{ font-size: 12px; }-->


原则2:#ID > .class > 标签

demo1:

代码如下:


<style type="text/css">
#id3 { font-size: 25px; }
.class3{ font-size: 18px; }
span{font-size:12px}
</style> </p> <p><span id="id3" class="class3">我是多大字号?</span> <!--运行结果:#id3 { font-size: 25px; }-->


原则3:越具体越牛B

demo1:

代码如下:


<style type="text/css">
.class1 .class2 .class3{font-size: 25px;}
.class2 .class3{font-size:18px}
.class3 { font-size: 12px; }
</style> </p> <p><div class="class1">
<p class="class2"> <span class="class3">我是多大字号?</span> </p>
</div> <!--运行结果:.class1 .class2 .class3{font-size: 25px;}-->


原则4:标签#ID > 标签.class

demo1:

代码如下:


<style type="text/css">
span#id3{font-size:18px}
#id3{font-size:12px}
span.class3{font-size:18px}
.class3{font-size:12px}
</style></p> <p><span id="id3">我是多大字号?</span>
<span class="class3">我是多大字号?</span> <!--运行结果:span#id3{font-size:18px} | span.class3{font-size:18px}-->


最后:当原则之前冲突的时候,原则1 > 原则2 > 原则3 > 原则4

!important

IE6到底认不认识!important???

答:认识,但是有一个小bug。

例如:

代码如下:


<style>
#ida {size:18px}
.classb { font-size: 12px; }
</style></p> <p><div id=“ida” class=“classb”>!important测试:18px</div>


加入!important

代码如下:


<style>
#ida{font-size:18px}
.classb{ font-size: 12px !important; }
</style></p> <p><div id=“ida” class=“classb”>!important测试:12px</div>


IE6 BUG:

代码如下:


<style>
.classb{ font-size: 18px !important; font-size: 12px }
</style></p> <p><div class=“classA”>!important测试:12px</div>


原因和办法:

这里在ie6下是12像素的字,而其他浏览器下是18px的字。

但是当我们把样式改一下,!important放在后面,即.classb{ font-size: 12px;font-size: 18px !important; },那么ie6下和其他浏览器一样也是18px的字。

以上是“面试时可能被问到的CSS问题有哪些”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!

新闻名称:面试时可能被问到的CSS问题有哪些-创新互联
转载注明:https://www.cdcxhl.com/article34/ccsspe.html

成都网站建设公司_创新互联,为您提供网站设计云服务器Google小程序开发微信公众号响应式网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设