为表达最原作者的尊重,文章只字未改,原文地址为:
http://www.cnblogs.com/lovelq522/archive/2010/11/26/1888433.html
HTML的style属性提供了一种改变HTML样式的通用方法。style是在HTML4版本中引用的,它是一种首选的改变HTML元素样式的方法。可以使用style直接的将样式添加到HTML元素中,或者使用独立的style文件在样式表中间接的定义。
随着HTML的发展,有很多标签和属性即将被废弃,也就是说在未来的HTML版本中将不再支持这些属性和标签,我们应该避免使用这些熟悉和标签。当然这些废弃的标签和属性所起的作用都有更好的方法来实现,比如:使用style属性。
下面是一些废弃的标签和熟悉:
标签 | 描述 |
---|---|
<center> | 定义居中的内容。 |
<font> 和 <basefont> | 定义 HTML 字体。 |
<s> 和 <strike> | 定义删除线文本(使用del代替) |
<u> | 定义下划线文本 |
属性 | 描述 |
align | 定义文本的对齐方式 |
bgcolor | 定义背景颜色 |
color | 定义文本颜色 |
以上的标签和属性都可以使用style属性代替,来实现其所起的作用。、
以下是几个style属性的实例:
- 使用style属性改变背景颜色(bgcolor作用)
1
2
3
4
5
6
|
<
span
style
=
"font-size: 12pt;"
><
html
>
<
body
style
=
"background-color:yellow"
>
<
h1
stye = "background-color:red>This is a Heading</
h1
>
<
p
style = "background-color:green>This is a Paragraph</
p
>
</
body
>
</
html
></
span
>
|
style属性淘汰了旧的"bgcolor"属性。
- 使用style属性设置颜色、字体和尺寸
1 < html > 2 < body > 3 < h1 style = "font-family:verdana" > A Heading </ h1 > 4 < p style = "font-family:arial;color:red;font-size:20px;" > A Paragraph </ p > 5 </ body > 6 </ html >
style属性淘汰了旧的<font>标签。
- style属性设置文本对其方式
1 < html > 2 < body > 3 < h1 style = "text-align:center;" > A Heading </ h1 > 4 < p > The heading above is aligned to the center of the page </ p > 5 </ body > 6 </ html >
style属性淘汰了align属性。
当然,style元素远远不是上面所说的那么简单,还有很多的值来定义HTML元素的样式。在以后,我将继续学习。