Archive for 十一月 11th, 2009

what beautiful HTML looks like

请看原文:http://css-tricks.com/what-beautiful-html-code-looks-like/

  • HTML5 – HTML5 and it’s new elements make for the most beautiful HTML yet.
  • DOCTYPE – HTML5 has the best DOCTYPE ever
  • Indentation – Code is indented to show parent/child relationships and emphasize hierarchy.
  • Charset – Declared as first thing in the head, before any content.
  • Title – Title of the site is simple and clean. Purpose of page is first, a separator is used, and ends with title of the site.
  • CSS – Only one single stylesheet is used (media types declared inside stylesheet), and only served to good browsers. IE 6 and below are served a universal stylesheet.
  • Body – ID applied to body to allow for unique page styling without any additional markup.
  • JavaScript – jQuery (the most beautiful JavaScript library) is served from Google. Only a single JavaScript file is loaded. Both scripts are referenced at the bottom of the page.
  • File Paths – Site resources use relative file paths for efficiency. Content file paths are absolute, assuming content is syndicated.
  • Image Attributes – Images include alternate text, mostly for visually impaired uses but also for validation. Height and width applied for rendering efficiency.
  • Main Content First – The main content of the page comes after basic identity and navigation but before any ancillary content like sidebar material.
  • Appropriate Descriptive Block-Level Elements – Header, Nav, Section, Article, Aside… all appropriately describe the content they contain better than the divs of old.
  • Hierarchy – Title tags are reserved for real content, and follow a clear hierarchy.
  • Appropriate Descriptive Tags – Lists are marked up as lists, depending on the needs of the list: unordered, ordered, and the underused definition list.
  • Common Content Included – Things common across multiple pages are inserted via server side includes (via whatever method, language, or CMS that works for you)
  • Semantic Classes – Beyond appropriate element names, classes and IDs are semantic: they describe without specifying. (e.g. “col” is much better than “left”)
  • Classes – Are used any time similar styling needs to be applied to multiple elements.
  • IDs – Are used any time an element appears only once on the page and cannot be targeted reasonably any other way.
  • Dynamic Elements – Things that need to be dynamic, are dynamic.
  • Characters Encoded – If it’s a special character, it’s encoded.
  • Free From Styling – Nothing on the page applies styling or even implies what the styling might be. Everything on the page is either a required site resource, content, or describing content.
  • Comments – Comments are included for things that may not be immediately obvious upon reviewing the code.
  • Valid – The code should adhere to W3C guidelines. Tags are closed, required attributes used, nothing deprecated, etc.

在不添加标签的情况下解决浮动问题

在不添加标签的情况下解决浮动问题:

<div id=”A”>

<div id=”B” style=”float:left”></div>

</div>

================回答问题的分割线==================

#A { overflow:hidden; zoom:1;}

#A:after { content:”.”; height:0; display:block;clear: both;visibility:hidden;}

================答案解释的分割线==================

对于 IE 浏览器:使用了 zoom:1 来触发 haslayout

zoom语法:
zoom : normal | number
参数:
normal :  使用对象的实际尺寸
number : 百分数|无符号浮点实数。浮点实数值为1.0或百分数为100%时相当于此属性的normal值 
说明:
设置或检索对象的缩放比例。
示例:
div {zoom : 0.5; }

—————————-通俗语言—分割线—————————-

用css中的zoom属性可以让网页实现IE7世界之窗遨游中的放大缩小功能。
比如你想让你的网页缩小为原来的一半,那么就在body中加入style=”zoom:0.5″,如:
<body style=”zoom:0.5″>

对非 IE 浏览器:使用:after 伪元素在元素之后添加内容。

  1. 用content属性添加用于清除的额外内容,一般为“.”。
  2. 设display:block;因为display的默认值是”inline”, 不能收到clear的特性。
  3. 将清除容器的高度设为零,height:0。
  4. 清除浮动。
  5. 可见度设为隐藏。

:after 伪元素通常和content配合使用,IE不支持此伪元素,非IE 浏览器支持,所以并不影响IE/WIN浏览器。( IE 8 支持 content 属性,但对:after 伪元素的支持并不完全。)

—————————什么是:after———————————

:after伪元素允许在元素内容的最后面插入生成内容。默认地,这个伪元素是行内元素,不过可以使用属性 display 改变这一点。

此样式会在每个 h1 元素之后插入一张图片:
h1:after{
content:url(image.gif);}

================额外话的分割线==================

<div id=”A”>

<div id=”B” style=”float:left;float:none;”></div>

</div>

这样虽然可以真的,完完全全的清除浮动,但并非我们所需要的。


Copyright © 1996-2010 Chesanqi's Web World. All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress