惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - Shake. Wang's blog

解决sqlserver2005中文版与vs2005的WebApplicationProject的冲突问题 终极解决MagicAjax提交中文表单乱码的问题 Google的使命 - Shake. Wang's blog MagicAjax的中文问题 给web用户控件自定义后台事件 [导入]再谈css--如何针对不同位置的元素使用不同的风格 [导入][转]台湾鸿海总裁郭台铭给员工的一封邮件,很有借鉴意义 [导入]Unable to get the project ile from the web server错误的解决方法 [导入]ASP.NET 2.0 的内部变化 [导入]VSTS新鲜感触。。。 Blogger 的传说 超女运动终于谢幕了 基于MasterPage和UserControl的网站架构模式 也说: 谁来重燃开发者的激情 WebApplication的多国语言实现思路 cs第二次整容... 寻找丢失的iexplore进程 伟大架构师的秘密 抗战60周年祭
[导入]当css遇到xhtml--从display:inline到float:left - Shake. Wang's blog
Shake. Wang' · 2006-06-18 · via 博客园 - Shake. Wang's blog

几天前,写了一个tab control ,风格如下:

我使用了css来描述这个风格,html和css代码如下:

<ul> <li><a href="#" class="selected">文件</a></li> <li><a href="#">编辑</a></li> <li><a href="#">视图</a></li> <li><a href="#">站点</a></li> <li><a href="#">编译</a></li> <li><a href="#">工具</a></li> </ul>

ul { border-bottom:solid 1px #999999; border-left:solid 1px #999999; height:30px; width:100%; margin-left:0px; } li

{ border-top:solid 1px #999999; border-bottom:solid 0px #999999; border-left:solid 1px #999999; border-right:solid 1px #999999; background-color:#cccccc; width:100px; height:30px; display:inline; list-style-type:none; margin-left:-1px; margin-bottom:-2px; text-align:center; padding-top:10px; } .selected {border-top:solid 1px #999999; border-bottom:solid 0px #999999; border-left:solid 1px #999999; border-right:solid 1px #999999; background-color:#eaeaea; width:100px; height:30px; display:inline; list-style-type:none; margin-left:-1px; margin-bottom:-2px; text-align:center; padding-top:10px; }

在一个master page上使用没有任何问题。下午,在将这个tab control 拖到一个vs2005生成的页面上,运行的时候,发现效果竟然变成这个样子:

同样一段代码,同样的浏览器,怎么会出现不同的效果? 仔细检查后,发现原来在master page里之所以正常是因为master page使用的是html4.0,而现在的新的页面是使用xhtml1.0来定义,难道是由于xhtml的严格定义要求引起的? 赶快去w3c以及其他资源网站查资料,最后终于发现根本的原因。

原来,以前的写法一直都是错误的。由于默认情况下,“li” 元素一直是竖直排列的,所以,我就使用了 display:inline 强制让它在行的方向排列,以达到我想要的效果,但是,在xhtml里,这种不严谨的写法是不被支持的,所以,这里设置高度、宽度都没有任何作用。在格式化xhtml标签时,更加强化了 “box”的概念,要想使用一些margin,padding等填充效果,就必须先将元素转变成 box 元素,然后就可以设置想要的效果了。那么,如何将一个元素转变成 box 元素? 答案是: 可以使用 float:left/right 的方式来把元素漂浮起来,变成一个个的box,这样就可以任意使用 box 元素支持的css属性了。

基于以上的思路,我将上面css里的display:inline修改掉,变成float:left,一切都ok了!

以上只是一个特例,在html4.0转到xhtml的过程中,会有不少的css效果都会发生转变,不过,这种转变是有规律和准则的,只要掌握了这种思想,应该能解决大部分问题。


文章来源:http://community.hf-mstc.org/cs/blogs/shakewang/archive/2006/06/18/2793.aspx