面试时可能被问到的一些CSS问题

所属分类: 网页制作 / 应用技巧 阅读数: 346
收藏 0 赞 0 分享

仅以此篇缅怀那些笔试100次,问100次的CSS问题。

问:

  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;}
5 id选择符(#) id选择符具有唯一性,在页面中不能重复使用 #header{width:300px;}
6 class选择符(.) 可以在页面中重复使用 .title{width:300px;}
7 IEhack选择符(_、*、\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的字。

 

更多精彩内容其他人还在看

出色的美工/网页设计人员需要掌握的7项技能

在互联网这行也有几年经验了,作为程序开发,经常和前端开发打交道,从和他们合作的过程中,我对美工或者网页设计有些认识,如何成为一个出色的,出类拔萃的前端开发,我觉得应该要做到下面7点
收藏 0 赞 0 分享

网页设计师需要的知识体系有哪些

设计师需要哪些体系呢
收藏 0 赞 0 分享

从四个方面谈谈Web标准的价值所在 附思维导图

清清楚楚的明白Web标准的价值!Web标准的价值相信没人会不知道,不理睬。可是具体能做什么,能不能很好的作为一个规范或者指标去诊断网站存在的问题,能不能列出一张清单,清清楚楚地看到它的价值呢
收藏 0 赞 0 分享

为什么要少用Iframe的几个原因分析

iframes 提供了一个简单的方式把一个网站的内容嵌入到另一个网站中。但我们需要慎重的使用iframe。iframe的创建比其它包括scripts和css的 DOM 元素的创建慢了 1-2 个数量级
收藏 0 赞 0 分享

百度网盟环境下的广告投放技巧(图文教程)

百度的广告投放是有技巧的.我们来谈一下吧
收藏 0 赞 0 分享

10件优秀Web开发者提升开发能力必知的事

开发工作不仅仅只是写代码,这句话来自3EV网站的Dan Frost,他在一篇文章中阐述了开发过程中应该注意的一些事项
收藏 0 赞 0 分享

不是中国才有的特色:文化差异下的网页开发

这是一篇老外写的博客,详述了他眼中因文化差异导致的网页开发问题。“特色”并不是只有中国才有,或许作为中国的设计师,也需要考虑到印尼特色、新加坡特色……
收藏 0 赞 0 分享

负距离(换位思考)-相互影响的迭代过程

产品经理把握功能 功能-指事物或方法所发挥的有利作用 .比如实用性,操作性
收藏 0 赞 0 分享

谈谈设计中的用户体验背后的8个用户本能

用户体验背后有哪些用户本能呢
收藏 0 赞 0 分享

交互设计中关于是选择分页还是加载的问题讲解

一篇文章是分页还是全捕出来是一个问题
收藏 0 赞 0 分享
查看更多