div+css

浏览器开发者工具

1. Firebug
对于网页开发人员来说,Firebug是Firefox浏览器中最好的插件之一。它可以对已有的样式进行修改或者添加新的样式,并且直接在页面上预览效果。详细应用情况可以参看一峰同学的这篇文章

2. IE8
对于网页开发人员来说,IE系列一直是个挥之不去的噩梦。IE6/7见最后“IETester”的介绍,IE8原生了开发者工具,虽然跟Firebug相比差点,但也有它自己的特色,比如集成了Firefox下Web Developer插件的功能;新的标尺和取色工具;设置IE7标准/IE8标准/怪癖模式三种兼容模式等等。请看:教程一教程二

3. Safari
Safari的开发者工具默认安装的时候没有启用,可以通过“偏好设置” -> “高级” -> 勾选 “在菜单中显示‘开发’菜单”启用,启用后即可通过菜单栏打开,也可以单击鼠标右键然后“检查元素”。Safari的开发者工具与Firebug基本差不多但也有区别,比如不能新建一个样式,只能修改已有样式的值。Safari有个特点就是可以改变用户代理,从而将自己识别为另一个浏览器,看来Safari还在缅怀上个世纪的浏览器检测大战。网上对Safari的介绍不多,官网应该是比较详尽的。

4. Chrome
Google Chrome与Apple Safari同为Webkit内核,开发者工具长的一个样。右击鼠标“审查元素”即可打开,需要知道的是Chrome3.0的开发者工具还是英文版。

5. Opera
Opera的开发者工具叫做Opera 蜻蜓,与Firebug一样的大同小异,Opera 9.5 及以上版本通过“工具”->”高级”->”开发者工具”启用。可以下载 Opera 调试菜单来配合 Opera 蜻蜓。在我的工作中对Opera的接触不多,所以详细情况还是看看官网的介绍,发烧友级别的可以去论坛逛逛。

6. IETester
IETester是没有装虚拟机的朋友测试IE兼容性的必备软件。而IETester的团队之前是做IE浏览器的网页开发插件DebugBar的,自然DebugBar插件也可以整合进IETester。追求代码完美,被IE烤的焦头烂额的朋友可以在这里下载,使用请点这里


IE8的hack

1.样式值后面直接跟\9,可区别IE类浏览器和非IE浏览器

padding-bottom:15px;

padding-bottom:30px\9;

这样写IE类读取30px,非IE浏览器读取15px。然后再写IE7和IE6的hack区别出IE8:

padding-bottom:15px;           //所有浏览器

padding-bottom:30px\9;     //IE类浏览器可覆盖上行样式

*padding-bottom:20px;        //IE7和IE6(或者写成 +padding-bottom:20px; )可覆盖上行样式

_padding-bottom:17px;        //IE6 可覆盖上行样式

2.样式值后面直接跟\0,直接区别IE8和其他浏览器

padding-bottom:15px;     //所有浏览器

padding-bottom:30px\0;
这样写IE8读取30px,其他浏览器读取15px。padding-bottom:15px;
padding-bottom:30px\0;
这样写IE8读取30px,其他浏览器读取15px。-bottom:15px;
padding-bottom:30px\0;
这样写IE8读取30px,其他浏览器读取15pxpadding-bottom:15px;
padding-bottom:30px\0;
这样写IE8读取30px,其他浏览器读取15px。

padding-bottom:30px\0;    //IE8覆盖上行样式


网页截屏3

ciudadesycostas.com

ciudadesycostas.com

ciudadesycostas.com

ciudadesycostas.com


body标签到底是个啥?

和head一样,如果页面没有这个标签,浏览器会自动加上去。

1
2
3
4
5
6
7
<html>
<script type=“text/javascript”>
    window.onload = function(){
        alert(“Body个数是:”+document.getElementsByTagName(“body”).length);
    }
</script>
</html>

那么当页面中出现好几个body,浏览器又会怎么处理呢?
只会保留第一对出现的body,其他的都会删掉,但其他body里的内容仍然会保留,你也可以自己去测试一下,比较有意思。
body在各浏览器中都非常诡异,尤其是IE,问题多多。body除了像其他标签一样可以加class加id加事件,还有一些特性的性质,也可称之为bug。

一、IE中body默认的margin值为”15px 10px 15px 10px”,非IE的浏览器默认值为”8px 8px 8px 8px”。

二、body在默认情况下,背景色会突破border,不是它该占有的区域也会有它的背景。

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” 
”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<style type=“text/css”>
    html {border:1px solid green;}
    body {border:1px solid red;background:#FFFFCC;}
</style>
</head>
<body>
    A
</body>
</html>

三、如果给html一个背景,body的背景就会回到正常的区域,不再冲破border(你也可以发现html的背景也冲破了它自己的border)。可以利用这个性质,把body当成普通的标签来用,这样有时就能节省”wrap”之类的外包标签。可以给body宽度/高度,加背景,让它水平垂直居中等,都是可以做到的。

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” 
”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<style type=“text/css”>
    html {background:#CCFFFF;border:1px solid green;}
    body {border:1px solid red;width:500px;margin:0 auto;background:#FFFFCC;}
</style>
</head>
<body>
    HTML加了背景
</body>
</html>

四、在IE中,如果给html和body都加上背景,如果给body设置”width:500px;margin:0 auto;”,你会发现body中的position值为relative的元素在你改变浏览器窗口大小时,并不会随着body移动(其他浏览器正常),刷新一下才会跑过去。解决这个问题需要给body也加上position:relative,为什么这样就不知道了,或许可这样回答:“因为这是IE!”。

五、IE中body的默认z-index值为“0”,而其他浏览器为“auto”。这个还不能怪body,因为IE给所有标签的z-index默认值都是0,而其他浏览器都是给auto,除了Safari和Chrome(html为0,其他标签为auto)。

六、IE中光给body“overflow:hidden”是隐藏不了滚动条的,其他浏览器可以。这个貌似是body搞的鬼,事实上不是body的错,IE默认给了html“overflow:scroll”,其他浏览器都给visible,所以在IE中想要屏蔽滚动条的话,需要给html加上“oveflow:hidden”。

七、如果把html和body的overflow都设为visible,那么在IE就不会有滚动条,算正常的。但其他浏览器中,还是有滚动条,把其中任意一个改成hidden都会屏蔽滚动条,难道html和body还公用滚动条?

转自:xhlv童鞋


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.
1 Comment more...

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