在IE中使用first-child
来源:互联网 发布:淘宝网美的电饭煲 编辑:程序博客网 时间:2024/06/11 04:20
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
使用web standards做网页,经常需要定义某个父元素下的第一个子(child)元素或最后一个元素,以便将其与其他元素区分开来,有利于实现某些特殊需求。最浅显的例子是,导航项目间的竖线,我们往往通过border或者background来实现。特殊需求是,第一项左边无竖线或最后一项右边无竖线。那么区分第一项好呢,还是最后一项好?答案是明显的,逼不得已,不要用区别最后一项。按照一般的编程方法,控制第一项要比控制最后一项容易得多。
区分第一项的还有一个好处是,CSS有一个:first-child的伪元素(pseudo element)可以让我们轻而易举的选择第一个子元素。
遗憾的是,当前全球占有率最高的浏览器,IE6,并不支持这个伪元素。我们可以手工给第一个元素加上class然后再定义它。但这不是一个万无一失的办法,尤其对于页面规模达到一定数量大型网站,很容易挂一漏万。那么,让JavaScript来帮我们完成这件工作如何?
查看演示
在IE中,为每个属于first-child的li加上first-child的class,则CSS则可以这样书写了::first-child, .first-child { some rules here...}(有没有发现这样写很帅,一个是冒号,两点;一个是点号,一点 ),十分便于维护和管理。
p.s.希望哪位高手能够写出通用的first-child来,我这里的例子只针对li,能力有限!
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 在IE中使用first-child
- 在IE中使用first-child和last-child [半原][旧]
- jQuery中:first,:first-child,first()的使用区别
- jQuery中:first,:first-child,first()的使用区别
- first-child 和 last-child的使用
- 【实用随记】ie下不支持first-child,last-child
- 在css选择器中:first-child与:first-of-type的用法
- CSS3中first-child、last-child、nth-child、nth-last-child
- CSS中first-child和nth-child的讲解
- CSS中first-child和nth-child的讲解
- :first-child
- IE下的伪类:first-child和:last-child版本支持问题
- jquery 中 first 与 first-child选择器的区别
- jQuery中:first和:first-child的区别
- 在IE中使用JavaScript
- 在IE中使用firebug
- 在IE中使用firebug
- jQuery中 :first选择器,first()和:first-child选择器的区别
- 精彩的近乎完美的分页存储过程
- CSS规范学习:闭合浮动元素
- 自定义快速报表的打印预览窗口
- S-Record格式分析代码
- 如何在把超过固定长度的文字以"……"表示
- 在IE中使用first-child
- 打开并显示位图 mfc view
- 将面向对象的思想贯穿始终--谈Delphi开发(第二篇)
- web标准布局实例教程
- Windows 2000下优化Oracle9i性能
- 将面向对象的思想贯穿始终--谈Delphi开发(第一篇)
- 总结:用CSS进行网页样式设计攻略全集
- 在IE中直接连接SQL数据库
- Delphi精品书籍推荐