CSS allows to apply a solid color as a background, and also allows the use of background images to create quite complex effects.
You can use the background-color attribute to set the background color for the element. This property accepts any legal color value.
For example:
p {background-color: gray;}
To put the image into the background, you need to use background- image attribute. The default value of the background-image property is none, which means no image is placed on the background. If you need to set a background image, you must set a URL value for this attribute:
body {background-image: url(/i/eg_bg_04.gif);}
if necessary To tile the background image on the page, you can use the background-repeat attribute.
The attribute value repeat causes the image to be tiled both horizontally and vertically, as is usual for background images. repeat-x and repeat-y cause the image to be repeated only in the horizontal or vertical direction respectively, while no-repeat does not allow the image to be tiled in any direction.
By default, the background image will start from the top left corner of an element. Please see the following example:
body
{
background-image: url(/i/eg_bg_03.gif);
background-repeat: repeat-y;
}
You can use the background-position property to change the position of the image in the background.
The following example centers a background image within the body element:
body
{
background-image:url('/i/eg_bg_03.gif');
background-repeat:no-repeat;
background-position:center;
}
There are many ways to provide a value for the background-position property. First, there are some keywords you can use: top, bottom, left, right, and center. Typically, these keywords will appear in pairs, but that's not always the case. You can also use length values like 100px or 5cm and finally you can use percentage values. Different types of values have slightly different placement of the background image.
If the document is relatively long, when the document is scrolled down, the background image will also scroll with it. When the document is scrolled beyond the image, the image disappears. You can prevent this scrolling via the background-attachment property. Through this attribute, you can declare that the image is fixed relative to the visual area, so it will not be affected by scrolling:
<p class="sycode"> <p class="sycode"> body { background-image:url(/i/eg_bg_02.gif); background-repeat:no-repeat; background-attachment:fixed } </p> </p>
通过文本属性,您可以改变文本的颜色、字符间距,对齐文本,装饰文本,对文本进行缩进,等等。
p {text-indent: -5em;}
h1{text-align:center;}
p {word-spacing: 30px;}
h4 {letter-spacing: 20px}
Attribute value:
h1 {text-transform: uppercase}
Attribute value:
a {text-decoration: none;}
[Note: For inline elements, only when the unicode-bidi attribute is set The direction attribute is only applied when it is embed or bidi-override. 】
Attribute value:
p {word-direction : rtl;}
The white-space attribute affects the user agent's handling of spaces, newlines, and tab characters in the source document. Details:
值 | 空白符 | 换行符 | 自动换行 |
pre-line | 合并 | 保留 | 允许 |
normal | 合并 | 忽略 | 允许 |
nowrap | 合并 | 忽略 | 不允许 |
pre | 保留 | 保留 | 不允许 |
pre-wrap | 保留 | 保留 | 允许 |
h1 {font-family: Georgia;}
h1 {font-size:60px;}
h2 {font-size:40px;}
p {font-size:14px;}
属性值:
p.normal {font-style:normal;}
p.italic {font-style:italic;}
p.oblique {font-style:oblique;}
p {font-variant:small-caps;}
p.normal {font-weight:normal;}
p.thick {font-weight:bold;}
p.thicker {font-weight:900;}
ul li {list-style-image : url(xxx.gif)}
属性值:
ul{list-style-position:inside;}
ul {list-style-type : square}
属性值:
table{border-collapse:collapse;}
table{border-spacing:10px 50px;}
属性值:
caption{caption-side:bottom;}
属性值:
table{empty-cells:hide;}
属性值:
table{table-layout:fixed;}
轮廓(outline)是绘制于元素周围的边框线,可起到突出元素的作用。
CSS outline 属性规定元素轮廓的样式、颜色和宽度。
p{outline-color:#00ff00;}
属性值:
p{outline-style:dotted;}
p{outline-width:5px;}