锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鍦ㄨ繖绔犳垜浠皢瀛︿範鍒幫細
1.Fixed- and flexible-width rounded-corner boxes
2.The sliding doors technique
3.Mountaintop corners
4.CSS drop shadows
5.PNG transparency support for Internet Explorer 5.x and above
6.Image replacement
鍩烘湰鐨勮儗鏅浘鐗?/strong>
body {
background:url(pattern.gif);
}
body {
background: #ccc url(gradient.gif) repeat-x;
}
#branding {
width: 700px;
height: 200px;
background:url(/images/branding.gif) no-repeat;
}
h1 {
padding-left: 30px;
background: url(/images/bullet.gif) no-repeat left center;
}
h1 {
padding-left: 30px;
background: url(/images/bullet.gif) no-repeat 0 50%;
}
Rounded-corner boxes
.box {
width: 418px;
background: #effce7 url(images/bottom.gif) no-repeat left bottom;
}
.box h2 {
background: url(images/top.gif) no-repeat left top;
}
.box h2 {
padding: 10px 20px 0 20px;
}
.box p {
padding: 0 20px 10px 20px;
}
<div class="box">
<h2>Headline</h2>
<p>Content</p>
</div>
.box {
width: 424px;
background: url(images/bg-tile.gif) repeat-y;
}
.box h2 {
background: url(images/bg-top.gif) no-repeat left top;
padding-top: 20px;
}
.box .last {
background: url(images/bg-bottom.gif) no-repeat left bottom;
padding-bottom: 20px;
}
.box h2, .box p {
padding-left: 20px;
padding-right: 20px;
}
<div class="box">
<h2>Headline</h2>
<p class="last">Content</p>
</div>
Flexible rounded-corner box
.box {
width: 20em;
background: #effce7 url(images/bottom-left.gif)
no-repeat left bottom;
}
.box-outer {
background: url(images/bottom-right.gif) no-repeat right bottom;
padding-bottom: 5%;
}
.box-inner {
background: url(images/top-left.gif) no-repeat left top;
}
.box h2 {
background: url(images/top-right.gif) no-repeat right top;
padding-top: 5%;
}
.box h2, .box p {
padding-left: 5%;
padding-right: 5%;
}
<div class="box">
<div class="box-outer">
<div class="box-inner">
<h2>Headline</h2>
<p>Content</p>
</div>
</div>
</div>
Mountaintop corners
.box {
width: 20em;
background: #effce7 url(images/bottom-left.gif)
no-repeat left bottom;
}
.box-outer {
background: url(images/bottom-right.gif) no-repeat right bottom;
padding-bottom: 5%;
}
.box-inner {
background: url(images/top-left.gif) no-repeat left top;
}
.box h2 {
background: url(images/top-right.gif) no-repeat right top;
padding-top: 5%;
}
.box h2, .box p {
padding-left: 5%;
padding-right: 5%;
}
<div class="box">
<div class="box-outer">
<div class="box-inner">
<h2>Headline</h2>
<p>Content</p>
</div>
</div>
</div>
Drop shadows
Easy CSS drop shadows
.img-wrapper {
background: url(images/shadow.gif) no-repeat bottom right;
clear: right;
float: left;
}
.img-wrapper img {
margin: -5px 5px 5px -5px;
}
<div class="img-wrapper"><img src="dunstan.jpg" width="300"
height="300" alt="Dunstan Orchard" /></div>
.img-wrapper img {
background-color: #fff;
border: 1px solid #a9a9a9;
padding: 4px;
margin: -5px 5px 5px -5px;
}
.img-wrapper {
background: url(images/shadow.gif) no-repeat bottom right;
clear: right;
float: left;
position: relative;
}
.img-wrapper img {
background-color: #fff;
border: 1px solid #a9a9a9;
padding: 4px;
display: block;
margin: -5px 5px 5px -5px;
position: relative;
}
Drop shadows a la Clagnut
.img-wrapper {
background: url(images/shadow.gif) no-repeat bottom right;
float:left;
line-height:0;
}
.img-wrapper img {
background:#fff;
padding:4px;
border:1px solid #a9a9a9;
position:relative;
left:-5px;
top:-5px;
}
Fuzzy shadows
.img-wrapper {
background: url(images/shadow.gif) no-repeat right bottom;
float: left;
}
.img-wrapper div {
background: url(images/mask.png) no-repeat left top !important;
background: url(images/mask.gif) no-repeat left top;
padding: 0 5px 5px 0;
float: left; /* :KLUDGE: Fixes problem in IE5.2/Mac */
}
.img-wrapper img {
background-color: #fff;
border: 1px solid #a9a9a9;
padding: 4px;
}
<div class="img-wrapper">
<div>
<img src="dunstan.jpg" width="300" height="300" alt="Dunstan" />
</div>
</div>
Onion skinned drop shadows
.img-wrapper {
background:url(images/shadow.gif) no-repeat right bottom;
float: left;
}
.img-outer {
background:url(images/bottom-left2.gif) no-repeat left bottom;
float: left; /* :KLUDGE: Fixes problem in IE5.2/Mac */
}
.img-inner {
background:url(images/top-right2.gif) no-repeat top right;
padding: 0 5px 5px 0;
float: left; /* :KLUDGE: Fixes problem in IE5.2/Mac */
}
.img-wrapper img {
background-color: #fff;
border: 1px solid #a9a9a9;
padding: 4px;
display: block;
}
<div class="img-wrapper">
<div class="img-outer">
<div class="img-inner">
<img src="images/dunstan.jpg" width="300" height="300"
alt="Dunstan" />
</div>
</div>
</div>
Image replacement
Fahrner Image Replacement (FIR)
h2 {
background:url(hello_world.gif) no-repeat;
width: 150px;
height: 35px;
}
span {
display: none;
}
<h2>
<span>Hello World</span>
</h2>
Phark
h2 {
text-indent: -5000px;
background:url(hello_world.gif) no-repeat;
width: 150px;
height:35px;
}
<h2>
Hello World
</h2>
Gilder/Levin method
h2 {
width: 150px;
height: 35px;
position: relative;
}
h2 span {
background: url(hello_world.gif) no-repeat;
position: absolute;
width: 100%;
height: 100%;
}
<h2>
<span></span>Hello World
</h2>
1.鐩掑瓙妯″紡鐨勫鏉傚拰鐗瑰緛
2.鎬庢牱騫朵笖涓轟粈涔堥〉杈圭┖鐧芥敹緙?br>3.緇濆浣嶇疆鍜岀浉瀵逛綅緗殑涓嶅悓
4.floating 鍜?clearing鎬庢牱宸ヤ綔
Box model recap
* {
margin: 0;
padding: 0;
}
#myBox {
margin: 10px;
padding: 5px;
width: 70px;
}
Margin collapsing
Positioning recap
Relative positioning 鐩稿浣嶇疆
#myBox {
position: relative;
left: 20px;
top: 20px;
}
Absolute positioning 緇濆浣嶇疆
#branding {
width: 700px;
height: 100px;
position: relative;
}
#branding .tel {
position: absolute;
right: 10px;
bottom: 10px;
text-align: right;
}
<div id="branding">
<p class="tel">Tel: 0845 838 6163</p>
</div>
Floating
Line boxes and clearing
.news {
background-color: gray;
border: solid 1px black;
}
.news img {
float: left;
}
.news p {
float: right;
}
<div class="news">
<img src="news-pic.jpg" />
<p>Some text</p>
</div>
.news {
background-color: gray;
border: solid 1px black;
}
.news img {
float: left;
}
.news p {
float: right;
}
.clear {
clear: both;
}
<div class="news">
<img src="news-pic.jpg" />
<p>Some text</p>
<div class="clear"></div>
</div>
鏇寸畝鎹風殑鏂規硶濡備笅:
.news {
background-color: gray;
border: solid 1px black;
float: left;
}
.news img {
float: left;
}
.news p {
float: right;
}
<div class="news">
<img src="news-pic.jpg" />
<p>Some text</p>
</div>
鎴戞墍鐢ㄧ殑宸ュ叿
UltraEdit
IE 嫻忚鍣?/p>
絎?绔犅?鎵撲笅鍩虹
鍦ㄨ繖绔犳垜浠皢瀛︿範鍒幫細
1.涓涓ソ鐨勭粨鏋勭殑閲嶈鎬у拰鏈夋剰涔夌殑鏂囨。
2.緙栧啓鏈浼樻柟娉?br />3.鍏辨湁鐨勭紪鍐欓敊璇?br />4.鏂囨。綾誨瀷錛孌OCTYPE switching鍜屾祻瑙堝櫒鏍峰紡
5.寤虹珛鑷繁鐨勬牱寮?br />6.灞傚彔錛岀壒寰佸拰緇ф壙
(X)html鍖呮嫭寰堝鍏冪礌銆備緥濡?/p>
h1,h2,..
ul,ol,dl
strong,em
blockquote,cite
abbr,acronym,code
fieldset,legend,label
caption,thead,tbody,tfoot聽
IDs 鍜岀被鍚?class names)
<ul id="mainNav">
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact</a></li>
</ul>
Divs 鍜?spans
<div id="mainNav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</div>
綆鍖?/p>
<ul id="mainNav">
<li>Home</li>
<li>About Us</li>
<li>Contact</li>
</ul>
<h2>Where鈥檚 Durstan?</h2>
<p>Published on <span class="date">March 22nd, 2005</span>
by <span class="author">Andy Budd</span></p>
DOCTYPE switching
(X)HTML 鏂囨。閬靛驚鐨勬枃妗g被鍨嬪畾涔?DTD)銆?/p>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
寤虹珛鑷繁鐨勬牱寮?/font>
Common selectors
Type selectors
p {color: black;}
descendant selectors
li a {text-decoration: none;}
ID and class selectors
#intro {font-weight: bold;} #mainContent h1 {font-size: 1.8em;}
Pseudo-classes
/* makes all unvisited links blue */ /* makes all visited links green */ /* makes links red when hovered or activated */ /* makes table rows red when hovered over */ /* makes input elements yellow when focus is applied */
The universal selector
* {
Advanced selectors
Child and adjacent sibling selectors
#nav > li {font-weight: bold;} 瑕嗙洊 鍏辯敤
Attribute selectors
<abbr title="Cascading Style Sheets">CSS</abbr> abbr[title] {border-bottom: 1px dotted #999;} a[rel="nofollow"] { .intro {border-style: solid;} a[rel~="friend"] {background-image: url(friend.gif);} 聽
"
"
"
a {text-decoration: underline;}
h1 {font-weight: bold;}
.datePosted {color: green;}
<p id="intro">Some Text</p>
<p class="datePosted">24/3/2006</p>
#secondaryContent h1 {font-size: 1.2em;}
<div id="mainContent">
<h1>Welcome to my site</h1>
...
</div>
<div id="secondaryContent">
<h1>Latest news</h1>
...
</div>
a:link {color:blue;}
a:visited {color:green;}
a:hover, a:active {color:red;}
tr:hover {background-color: red;}
input:focus {background-color:yellow;}
聽聽聽聽聽聽聽
IE 6 瀵?:focus涓嶆敮鎸?/p>
padding: 0;
margin: 0;
}
<ul id="nav">
<li>Home</li>
<li>Services
<ul>
<li>Design</li>
<li>Development</li>
<li>Consultancy</li>
</ul>
</li>
<li>Contact Us </li>
</ul>
#nav li {font-weight: bold;}
#nav li * {font-weight: normal;}
h1 + p {font-weight: bold;}
<h1>Main Heading</h1>
<p>First Paragraph</p>
<p>Second Paragraph</p>
abbr[title]:hover {cursor: help;}
background-image: url(nofollow.gif);
padding-right: 20px;
}
[class="intro"] {border-style: dotted;}
<a href="John Hicks
</a>
]]>
鎴戠殑絎竴涓?/span> CSS
<html>
<head>
<title></title>
<style type="text/css">
p{
color : red ;
}
.date{
color : green ;
}
#intro {font-weight: bold;}
.datePosted {color: green;}
#mainContent h1 {font-size: 1.8em;}
#secondaryContent h1 {font-size: 1.2em;}
a:hover{
color : #FF0080 ;
}
a:active{
color : #0080FF ;
}
#nav li {font-weight: bold;}
</style>
</head>
<body>
<p>i'm red</p>
<a href="#">
浣犲ソ
</a>
<div id="mainNav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</div>
<h2>Where鈥檚 Durstan?</h2>
<p>Published on <span class="date">March 22nd, 2005</span>
by <span class="author">Andy Budd</span></p>
<p id="intro">Some Text</p>
<p class="datePosted">
<div id="mainContent">
<h1>Welcome to my site</h1>
...
</div>
<div id="secondaryContent">
<h1>Latest news</h1>
...
</div>
<ul id="nav">
<li>Home</li>
<li>Services
<ul>
<li>Design</li>
<li>Development</li>
<li>Consultancy</li>
</ul>
</li>
<li>Contact Us </li>
</ul>
</body>
</html>
聽聽聽聽聽聽