`
charrysong
  • 浏览: 50660 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

CSS Crib Sheet - css蝉意花园结语

阅读更多

CSS Crib Sheet

It's clear to anyone who has tried building a site or two with CSS that browser support still isn't perfect. In fact, depending on the complexity of your work, you may end up banging your head on your desk and swearing off Web design forever, for the sake of a nice, simple job like city planning or nuclear physics.

In that vein, it's important to realize that you're not alone. A whole community is working out the problems with standards-based design and sharing the knowledge with one another.

Coordinated by coauthor Dave Shea, one of the many resources now available is called the CSS Crib Sheet. Designed as a one-stop resource for common problems and solutions, the Crib Sheet is duplicated below. The most recent version is available at www.mezzoblue.com/css/cribsheet.

When in doubt, validate - 若不确信,那么就去验证

When debugging, you may save yourself headaches by simply validating your code first. Improperly formed XHTML/CSS will cause many a layout glitch. Validation is an important tool for learning how to find and correct mistakes. The W3C hosts both XHTML and CSS validators, available at http://validator.w3.org and http://jigsaw.w3.org/css-validator respectively.

Note that errors early on in the document may cause further errors elsewhere due to improper nesting or other reasons, which are often not true errors. We recommend fixing a few obvious errors and re-validating; you might find the total error count drastically reduced.

Build and test your CSS in the most advanced browser available before testing in others, not after - 创建并测试css时,首先在最高级,最先进的浏览器中进行,然后再考虑其它浏览器

If you build a site by testing it in an older browser, your code will end up relying on the less advanced and potentially broken rendering of that browser. You will likely be frustrated when a more standards-compliant browser renders it improperly, which is completely backward.

Instead, start with perfection and then test for the less able browsers. Your code will be more standards-compliant from the start, and you won't need to go to great lengths to support other browsers. Today this means you should test in Mozilla (Firefox), Safari, or perhaps Opera first, and then correct for Microsoft Internet Explorer.

When relying on floats for layouts, make sure they clear properly - 若用浮动实现布局,请确保正确地清除了浮动

Floats are tricky, and they don't always do what you expect. If you run into a situation where a floated element extends past the border of its containing element or just doesn't behave properly, make sure that what you're attempting to do is correct. See Eric Meyer's tutorial on the matter at his Complex Spiral Consulting Web site (www.complexspiral.com/publications/containing-floats).

Margins collapse; apply padding or a border to avoid - 为元素应用内边距或边框来避免外边距重叠

You may struggle with extra white space where you don't want any, or no white space where you actually want some. If you're using margins, collapsing is most likely the culprit. Andy Budd explains what you can expect on his Web site (www.andybudd.com/archives/2003/11/no_margin_for_error).

Try to avoid applying padding/borders and a specific width or height to an element - 避免同时为元素指定明确的内边距、边框值与宽度、高度值

Internet Explorer 5.0 and 5.5 for Windows get the box model wrong, which often causes problems when relying on width or height values. There are ways around this (see http://tantek.com/CSS/Examples/boxmodelhack.html), but it's best to sidestep the issue if possible by simply applying a margin to child elements if a parent requires a specific width/height, or applying padding to the parent if the child requires the width/height.

Avoid the "Flash of Unstyled Content" in Internet Explorer 6 for Windows - 避免IE6“无样式内容瞬间”现象

If you rely on @import alone for external style, sooner or later you'll notice that Internet Explorer 6 for Windows "flashes" plain, unformatted HTML briefly before applying CSS. This can be avoided by linking your style sheet, or adding a script element to your page. See BlueRobot.com's "Flash of Unstyled Content" page (www.bluerobot.com/web/css/fouc.asp).

Don't rely on min-width/min-height - 不要依靠min-width或min-height属性

IE/Win doesn't support either. But it does treat width and height as if they were min-width or min-height, to a certain degree, so with a bit of filtering specific to Internet Explorer for Windows, you can achieve the same end result using width or height alone. For a specific example, see "min-height: fixed" at mezzoblue.com (mezzoblue.com/archives/2004/09/16/minheight_fi).

When in doubt, decrease percentage values - 尝试减少百分比值

Sometimes rounding errors will cause 50% + 50% to add up to 100.1%, which ends up breaking layouts. Try bumping the values down from 50% to 49%, or even 49.9%.

Content not showing up properly in Internet Explorer? - IE中没有完整的显示出内容

You may be suffering the "Peekaboo bug," especially if it shows up when the user hovers the pointer over a link. See Position Is Everything (www.positioniseverything.net/explorer/peekaboo.html) for the fix.

Make sure your desired effect actually exists - 确保要实现的效果确实存在

There are browser-specific CSS extensions that aren't in the official spec. Filters and scroll-bar formatting are proprietary code elements that won't work in anything but Internet Explorer, for example. If the validator tells you the code you're using isn't defined, chances are it's proprietary and won't work consistently across other browsers.

Remember "LoVe/HAte" linking - 牢记LoVe/HAte(爱恨)链接规则

When specifying link pseudo-classes, always do so in this order: link, visited, hover, active. Any other order won't work consistently. Consider using :focus as well, and modify the order to LVHFA (and remember this sequence with Matt Haughey's suggested mnemonic "Lord Vader's Handle Formerly Anakin").

Remember "TRouBLed" shorthand - 牢记TRouBLED(麻烦的)边框简写顺序

border, margin, and padding shorthand assumes a specific order, clockwise from the top: top, right, bottom, left. So margin: 0 1px 3px 5px; results in no top margin, a 1-pixel right margin, and so on. Remember the mnemonic "TRouBLe" and you'll always get the correct order.

Specify units for non-zero values - 为非零值标明单位

CSS requires you to specify units on all values of fonts, margins, and sizes. (The only exception is line-height, which doesn't require a unit but can accept one anyway.) The behavior of any particular browser when sizes aren't specified should not be relied upon. Zero is zero, however, be it px, em, or anything else; no units are necessary when the value is 0. Example: padding: 0 2px 0 1em;

Test different font sizes - 测试不同字体的大小显示

Advanced browsers like Mozilla and Opera allow the user to resize text no matter which sizing unit is used. Some users will assuredly have a differently sized default than you; try to accommodate as wide a range as possible to account for these variations.

Match cases between your HTML and CSS - 在HTML和CSS中统一大小写

CSS, and most browsers, are case-sensitive. Applying a class like 'homePage' is fine, provided you are consistent with your letter case across both CSS and HTML. Applying style rules to 'homepage' instead will cause problems in user agents that closely follow the CSS specification (like Mozilla).

Test embedded; launch imported - 测试时实用嵌入样式,发布时再改为外部链接方式

If you develop with a style sheet embedded between style tags within your HTML source, you eliminate any potential caching errors while testing. This can be very important when working with some older browsers. But make sure to move your CSS to an external file before launching, imported with @import or link; otherwise, the benefits of external CSS are lost.

Add obvious borders to help debug layouts - 用明显的边框辅助调试布局

A universal rule like * {border: solid 1px #f00;} can go a long way toward pinpointing a layout problem. Adding a border to specific elements can help identify overlapping and extra white space, which might not otherwise be obvious.

Don't use single quotation marks around paths for images - 指定图片路径时不要实用单引号

When placing a background image, quote marks are unnecessary, and Internet Explorer 5 for Macintosh won't pick up the image. Use double quotes, or none at all.

Be careful when styling links if you're using anchors - 若实用了锚点(anchor),那么在为超链接应用样式时要格外小心

If you use a classic anchor in your codea name="anchor"you'll notice that it picks up :hover and :active pseudo-classes. To avoid this, you'll need to use an id for anchors insteaddiv id="anchor"or style with a slightly more arcane syntax, :link:hover and :link:active. See www.dbaron.org/css/1999/09/links.

Don't link to empty style sheets as "placeholders" for future style sheets (like handheld or print media style sheets) - 不要链接空的样式表作为“占位符”(例如手持设备或应用于打印的样式表)

Internet Explorer 5 for Mac takes issue with the empty style sheet, and the page load time increases. Instead, have at least one rule (or perhaps even a comment) in the style sheet, or simply don't link to it.

转自:http://www.ok22.org/art_detail.aspx?id=166

分享到:
评论

相关推荐

    Crib Hunting-crx插件

    在CRIB狩猎我们的使命是简化您的财产搜索。 下载我们的扩展名,我们将自动建议您从阿联酋的前3名门户网站查看的房产列表(Dubizzle.com,PropertyFinder.ae,Bayut.com)因此您可以轻松跟踪,比较并在一个地方留空 ...

    crib.ninja-crx插件

    crib.ninja使得易于在线搜索公寓。 此扩展允许您将Apartments保存到CRIB.NINJA。 它们可以从打开的选项卡中保存,从打开页面的链接或通过书签图标。 在CRIB.NINJA中,您可以看到您实际关心的信息,如租金,尺寸,...

    crib_sheet:用于复制和粘贴查询的命令或教程

    综上所述,这个crib_sheet主要涵盖了Windows命令行(CMD)、Docker、GitHub、Kafka以及与CSS相关的命令行操作,提供了一套实用的工具和技巧,帮助用户更高效地在这些环境中复制和粘贴查询。在学习和使用这些技术时,...

    Digi Crib:数字纸牌板-项目开发

    【标题】"Digi Crib:数字纸牌板-项目开发"揭示了这是一个与游戏相关的技术项目,旨在创建一个数字化的纸牌游戏设备,可能是为了提高游戏体验或为那些喜欢传统游戏的人提供便利。"Digi Crib"可能是这个设备的特定...

    Preliminary Findings on Handmade Rattan Baby Crib andBassinet Designs Regarding.zip

    Preliminary Findings on Handmade Rattan Baby Crib andBassinet Designs Regarding.zip

    com_crib:Joomla,Jomla,шпаргалкапоанглийскому,

    `crib`在这里可能是“笔记”或“速查表”的意思,暗示这个组件是一个用于学习英语词汇的工具。 `com_crib`的主要功能是提供一个最小的词汇库,帮助用户阅读英文文档时理解并学习新的词汇。这尤其对初学者或需要扩大...

    2022NOC软件创意编程赛项真题C++初中-决赛(有解析)

    当遇到新的时间段与最新结束时间有冲突时,增加导购数量,并更新最新结束时间为新时间段的结束时间。 - **数据结构**:可以使用列表或者数组来存储时间段,并使用变量记录当前的导游数量和最新的结束时间。 - **算法...

    通过互联网控制圣诞节婴儿床-项目开发

    该项目名为“通过互联网控制圣诞节婴儿床”,其核心目标是实现远程控制圣诞装饰,特别是圣诞灯。...通过阅读“christmas-crib-controlling-via-internet-99fcda.pdf”文档,可以深入理解项目的技术细节和实现步骤。

    家居英语单词家居英语单词.doc

    7. Baby crib - 婴儿床:专为新生儿和婴儿设计的床,四周有栏杆保护。 8. Backless wall-unit - 不设背板的壁橱:一种没有后板的壁挂式储物单元,可以更好地融入墙面。 9. Bamboo furniture - 竹家具:使用竹子作为...

    20210522-西南证券-康宁杰瑞制药~B-9966.HK-PD~L1上市在即,抗体平台奠定长远发展.pdf

    公司凭借3个自主知识产权的技术平台——CRIB平台(双特异性抗体开发平台)、CRAM平台(混合抗体开发平台)和单域抗体平台——支撑其双抗药物管线的开发,展现了其强大的研发实力。 从市场角度来看,康宁杰瑞制药-B...

    20210615-国信证券-康宁杰瑞制药~B-9966.HK-双抗领跑者,立足差异化.pdf

    康宁杰瑞整合了多个特色技术平台,如单域抗体平台、CRIB双抗平台、CRAM混合抗体平台以及其他多功能平台,能够根据不同的生理学需求设计不同作用机制的药物,包括单域抗体、双抗、双抗ADC等创新分子。公司的研发管线...

    PMP案头手册.pdf

    使用工具如Microsoft Project的Crib-sheet可以帮助项目经理更有效地管理项目时间表。 6. **合同管理**:在涉及外部供应商或承包商的项目中,合同管理尤为重要。项目经理需理解和管理合同条款,确保所有合同义务得到...

    BS 5852-2006中文翻译版

    BS 5852-2006将测试结果分为若干等级,例如CRF(Cigarette Resistance to Flammability,香烟引燃测试)、Crib 5(Crib 5 Flammability Test,五号火源测试)等。不同的等级对应不同的防火要求,适用于不同场合的...

    20210621-华创证券-康宁杰瑞制药~B-9966.HK-深度研究报告:研发能力强大,双抗进入收获期.pdf

    本深度研究报告中提及的研发平台包括单域抗体、CRIB双抗、CRAM混合抗体、BADC/BIMC/TIMC/GIMC/CIMC等多种扩展平台,这些技术平台为康宁杰瑞提供了差异化和全球竞争力的产品管线。 康宁杰瑞的主打产品之一为KN046,...

    20210526-平安证券-康宁杰瑞-9966.HK-具备国际竞争力的双抗领域龙头企业.pdf

    康宁杰瑞的核心技术之一是其异二聚体双抗技术平台CRIB,该平台拥有较高的技术壁垒,使得公司能针对不同的靶点灵活设计并进行双抗的开发。康宁杰瑞的双抗产品不仅能够用于肿瘤免疫治疗,还在其他领域显示出巨大潜力。...

    家具行业常用的所有英语单词.doc

    5. **婴儿床** - *Baby crib*: 用于婴儿睡眠的安全围栏床。 6. **斗床** - *Bed with drawers*: 下方带有抽屉的床,可用于存放衣物等物品。 7. **沙发床** - *Sofa bed*: 平时用作沙发,需要时可以展开变成床的多...

    家具行业英语(整理完整版).doc

    6. Baby crib(婴儿床):专为婴儿设计的安全睡眠床。 7. Backless wall-unit(不设背板的壁橱):没有后板的壁挂式储物单元,通常用于展示物品。 8. Bamboo furniture(竹家具):使用竹子作为主要材料制成的环保...

    创新药研究框架之双抗行业分析:新兴技术,进入高速发展期(2021)(35页).pdf

    康宁杰瑞的CRIB技术平台助力其PD-L1〓CTLA-4双抗KN046的研发,同样具有全球领先地位;信达生物则布局了多个市场前景广阔的免疫靶点双抗;百济神州通过与海外药企合作,建立了国内最丰富的双抗管线;恒瑞医药的PD-L1...

    世上最全外贸家具类词汇.doc

    BBaby crib 是专为婴儿设计的安全睡眠床,Backless wall-unit 是一种没有背板的壁橱,节省空间且简洁。Bamboo furniture 以其环保和耐用性受到青睐,Banqueting chair 则是用于宴会或大型活动的椅子。Barstool 适用...

Global site tag (gtag.js) - Google Analytics