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

所属分类: 网页制作 / 应用技巧 阅读数: 332
收藏 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的字。

 

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

网页设计技巧:iframe自适应高度的问题

所谓iframe自适应高度,就是,基于界面美观和交互的考虑,隐藏了iframe的border和scrollbar,让人看不出它是个iframe
收藏 0 赞 0 分享

网页色彩对比与调和技巧分享

在对比状态下,色彩相互作用与单一色彩所带给人的感觉不一样,这种现象是由视觉残影引起的。当我们长时间注视某一彩色图像之后,再看白色背景时,眼前会出现色相、明度关系大体相仿的补色图像
收藏 0 赞 0 分享

网页色彩性质的分类

任何颜色都可以使用三原色——红、绿、蓝组合而成,三原色中只有红色是暖色,所以要判断作品颜色的冷暖,可以依据红色成分的多少而定。色调主要由明度与彩度组合而成,用来表示颜色的状态
收藏 0 赞 0 分享

使用Photoshop 制作网页线框图简单实用

这篇文章向大家介绍一套免费的Photoshop 线框图套件,这个线框图套件中包括通知、图片和视频,表单字段,标题,段落,项目符号列表,导航,广告横幅和普通网站的元素,如:搜索框,电子邮件注册表单等等
收藏 0 赞 0 分享

CSS使用技巧总结

偶尔看到一篇CSS常用技巧的总结文章,本人整理了一下,晒出来和大家分享,希望可以帮助你们
收藏 0 赞 0 分享

Web设计师如何制作Retina显屏设备的图片

到目前为止,我们知道苹果设备中支持Retina屏幕技术的有“iPhone”、“iPod”、“iPad”和“Macbook Pro”,这些设备能为用户呈现更细腻、平滑和高质量的图片效果,提高了用户的视觉体验。做为一名Web设计师如何为你的网站创建这些适合Retina显屏设备的图片呢
收藏 0 赞 0 分享

JPG,GIF及PNG各类型的图片格式详细解说

大家都知道网页上面的图像一般用jpg、gif和png这几种格式,他们有什么区别以及在什么场合下使用进行详细介绍看了下面的内容后你可能会有了自己的结论
收藏 0 赞 0 分享

组件化的前端开发流程详细说明

做前端的同学都知道,做的页面多了,东西就会乱,因此我们需要统一一个开发流程,开发流程的好坏,直接影响着页面开发的效率,间接影响游戏的时间为了更好的开发,我们做了一下总结
收藏 0 赞 0 分享

我们在囧途之UI工程师职业感慨

我是一名还不算特别优秀的UI工程师;这个要先说明一下UI不是美工,美工是以图片方案设计为主的岗位,而UI是指用户交互体验的设计
收藏 0 赞 0 分享

分享8款提高网页设计出色的CSS工具

当一个人需要编辑或修改网站设计,CSS发挥着重要的作用;今天就给大家分享8款非常出色的CSS工具,这些工具都是很出名的,能够解决开发当中常见的棘手问题,希望对你开发有所帮助
收藏 0 赞 0 分享
查看更多