{
color:green;
}
This is a blue, center-aligned paragraph.
This p element should not be blue.
| Property | Description | Values | CSS |
|---|---|---|---|
| height | Sets the height of an element | auto length % inherit | 1 |
| max-height | Sets the maximum height of an element | none length % inherit | 2 |
| max-width | Sets the maximum width of an element | none length % inherit | 2 |
| min-height | Sets the minimum height of an element | length % inherit | 2 |
| min-width | Sets the minimum width of an element | length % inherit | 2 |
| width | Sets the width of an element | auto length % inherit | 1 |
{
position:fixed;
top:30px;
right:5px;
}
{
position:relative;
left:20px;
}
{
position:relative;
top:-50px;
}
{
position:absolute;
left:100px;
top:150px;
}
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
{
float:right;
}
{
clear:both;
}
{
margin-left:auto;
margin-right:auto;
width:70%;
background-color:#b0e0e6;
}
CSS Syntax
p:first-child
{
color:blue;
}
I am a strong man.
I am a strong man.
p:first-child i
{
color:blue;
}
I am a strong man. I am a strong man.
I am a strong man. I am a strong man.
pseudo-elements
语法
selector:pseudo-element {property:value;}
或
selector.class:pseudo-element {property:value;}
{
content:url(smiley.gif);
}
| Selector | Example | Example description |
|---|---|---|
| :link | a:link | Selects all unvisited links |
| :visited | a:visited | Selects all visited links |
| :active | a:active | Selects the active link |
| :hover | a:hover | Selects links on mouse over |
| :focus | input:focus | Selects the input element which has focus |
| :first-letter | p:first-letter | Selects the first letter of every element |
| :first-line | p:first-line | Selects the first line of every element |
| :first-child | p:first-child | Selects every elements that is the first child of its parent |
| :before | p:before | Insert content before every element |
| :after | p:after | Insert content after every element |
| ) | p:lang(it) | Selects every element with a lang attribute value starting with "it" |
动态地改变图片的透明度:
img
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
img:hover
{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
显示图片的一部分:
img.next
{
width:43px;
height:44px;
background:url(img_navsprites.gif) -91px 0;
}
@media对于不同的媒体,使用不同的样式:
| Media Type | Description |
|---|---|
| all | Used for all media type devices |
| aural | Used for speech and sound synthesizers |
| braille | Used for braille tactile feedback devices |
| embossed | Used for paged braille printers |
| handheld | Used for small or handheld devices |
| Used for printers | |
| projection | Used for projected presentations, like slides |
| screen | Used for computer screens |
| tty | Used for media using a fixed-pitch character grid, like teletypes and terminals |
| tv | Used for television-type devices |
Attribute Selector
Hello world
Hello!
[key=value]只在key的值等于value时才应用样式。
[key~=value]只在key的值不等于value时才应用样式。