CSS
CSS是一种网页排版标准;是一门网页排版语言。系统把它学完、会用,仅需2个小时,IT人士必备工具。这里整理出说明书,涵盖常见CSS用法,要用了,来翻一翻这本说明书即可。
CSS主要就两件事情,一、选择要排版的网页元素;二、如何对网页元素进行排版。
第一件事情“选择要排版的网页元素”,是该说明书重点要描述的,至于,第二件事情,如何对网页元素进行排版,就需要用到大量的CSS属性,无非就是字体大小啦,空开多少啦,背景色啦之类的,总之就是小学出黑板报的那些伎俩而已,这个只要去看看FireBug即可,如下图,需要啥,拷拷过来用一下,即可。
CSS SELECTORS
CSS PROPERTIES
For example, the following selector will match all p elements with a class attribute that contains the value "warning":
p.warning {
declarations
}
A simple selector may contain more than one attribute selector and/or class selector; in such cases, the selector pattern matches elements whose attributes contain all the specified components. Here’s an example:
div.foo.bar { Element Type Selector和Class Selector结合使用,注意:中间没有空格,有空格的使用方法见下面
declarations
}
div.foo.bar[title^="Help"] {
declarations
}
The first example selector above matches div elements whose class attribute value contains both the words "foo" and "bar". The second example selector matches divelements whose class attribute values contains both the words "foo" and "bar", and whose title attribute values begin with the string "Help". To clarify further the html that would match the above selectors could be as follows:
<div class="foo bar">Matches first example</div>
<div class="foo bar" title="Help">Matches second example</div>
We can use the = operator to have an attribute selector match elements that have specific values:
input[type="submit"] {
declarations
}
This selector matches any input element that has a type attribute with a value equal to "submit".
We can use the |= operator to cause an attribute selector to match elements which have an attribute containing a list of hyphenated words that begin with a specific value:
[hreflang|="en"] {
declarations
}
This example selector matches any element that has an hreflang attribute containing a value of "en", whether or not that value is followed by a hyphen and more characters. In other words, it matches hreflang attribute values of "en", "en-US", "en-GB", and so on.
We can use the ~= operator to make an attribute selector match elements that have an attribute that contains a list of space-separated words, one of which is the specified value:
[class~="warning"] {
declarations
}
This selector matches any HTML element with a class attribute that contains a space-separated list of words, one of which is "warning". So it matches <p class="warning"> and <strong class="important warning"> and <div class="warning highlight">, but not <p class="my-warning"> or <ul class="warnings">.
We can group selectors using a comma (,) separator. The following declaration block will apply to any element that matches either of the selectors in the group:
td, th {
declarations
}
We can think of the comma as a logical OR operator, but it’s important to remember that each selector in a group is autonomous. A common beginner’s mistake is to write groups like this:
#foo td, th {
declarations
}
A beginner might think that the above declaration block will be applied to all td andth elements that are descendants of the element with an ID of "foo". However, the selector group above is actually equivalent to this:
#foo td {
declarations
}
th {
declarations
}
To achieve the true goal, write the selector group as follows:
#foo td, #foo th {
declarations
}
The combinator we use in a descendant selector is a whitespace character: a space, horizontal tab, carriage return, line feed, or form feed. Since whitespace characters are allowed around all combinators, you can include more than one whitespace character between the simple selectors in a descendant selector.
Consider the following HTML fragment:
<ul>
<li>Item 1</li>
<li>
<ol>
<li>Sub-item 2A</li>
<li>Sub-item 2B</li>
</ol>
</li>
</ul>
We’ll try to match elements in the above fragment using the selector below:
ul li { 注意:中间有空格了
declarations
}
This descendant selector will match all four li elements in the example HTML, because each of those elements has a ul element as its ancestor.
This selector matches all elements that are the immediate children of a specified element. The combinator in a child selector is a greater-than sign (>). It may be surrounded by whitespace characters, but if it is, Internet Explorer 5 on Windows will incorrectly treat it as a descendant selector. So the best practice is to eschew whitespace around this combinator.
Consider this HTML fragment:
<ul>
<li>Item 1</li>
<li>
<ol>
<li>Subitem 2A</li>
<li>Subitem 2B</li>
</ol>
</li>
</ul>
Let’s try to match elements in the above fragment with the selector below:
ul>li {
declarations
}
The child selector above will only match the two li elements that are children of theul element. It will not match the subitems, because their parent is the ol element.
下面是关于一些CSS小技巧:
关于DIV多层嵌套的margin-top的BUG
代码如下:
<div>上部层</div>
<div> <!–父层–>
<div style="margin-top:200px;">子层</div>
</div>
理想中的效果是父层和上部层贴边显示,子层距离父层顶部有200px的距离,在ie6,7中正常,但是在ff和IE8中却出现问题,子层和父层贴边了,而父层和上部层却间隔了200px。
当两个容器嵌套时,如果外层容器和内层容器之间没有别的元素,firefox和IE8会把内层元素的margin-top作用与父元素。
也就是说因为子层是父层的第一个非空子元素,所以使用margin-top会发生这个错误。
解决的办法有两个:
1、使用浮动来解决,即将子层代码改为:<div style="margin-top:200px;float:left";>子层</div>
2、使用padding-top来解决,即:
<div style="padding-top:200px;">
<div>子层</div>
</div>
padding vertical-align:middle; margin 综合用法,效果如下:
<div style="background:url(‘http://xiuxiu.baiyibai.com/website/wp-content/onepage/onepage_bg_11.jpg’) no-repeat center; width:620px; height:68px; margin:0 auto; padding:20px 0 0 340px;">
<div style=" font-size:14px; ">
<span style="vertical-align:middle;">墙纸秀秀联系方式:</span>
<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=2546911526&site=qq&menu=yes">
<img style="vertical-align:middle; margin-left:137px;" border="0" src="http://wpa.qq.com/pa?p=2:2546911526:42" alt="墙纸秀秀竭诚为您服务" title="墙纸秀秀竭诚为您服务">
</a>
<a target="_blank" href="http://amos1.taobao.com/msg.ww?v=2&uid=%E4%BA%91%E4%BD%93%E7%A7%91%E6%8A%80&s=1" >
<img style="vertical-align:middle; margin-left:78px;" border="0" src="http://amos1.taobao.com/online.ww?v=2&uid=%E4%BA%91%E4%BD%93%E7%A7%91%E6%8A%80&s=1" alt="墙纸秀秀竭诚为您服务" />
</a>
</div>
<div style=" font-size:14px; margin:7px 0 0 0;">咨询电话:0571-8692 5739(或5736) /  客服QQ:2546911526  /  阿里旺旺:云体科技</div>
</div>
IE6 margin-left的BUG
漂浮margin-left宽度为值的两倍 只要加 display:inline;