HTML样式

2020-07-09  本文已影响0人  InFatuated

style 属性用于改变Html元素的样式
实例:

<html>
<body style="background-color:PowderBlue;">

<h1>Look! Styles and colors</h1>

<p style="font-family:verdana;color:red">
This text is in Verdana and red</p>

<p style="font-family:times;color:green">
This text is in Times and green</p>

<p style="font-size:30px">This text is 30 pixels high</p>

</body>
</html>

HTML的style属性

style属性的作用:
提供了一种改变所有HTML元素的样式的通用方法。
样式是HTML4引入的,它是一种新的首选的改变HTML元素样式的方式。通过HTML样式,能够通过使用style属性直接将样式添加到HTML元素,或者间接地在独立的样式表中(CSS文件)进行定义。

不赞成使用的标签和属性

在HTML4中,有若干的标签和属性是被废弃的。被废弃(Deprecated)的意思是在未来版本的HTML和XHTML中将不支持这些标签和属性。
这里传达的信息很明确:请避免使用这些废弃的标签和属性!

应该避免使用下面这些标签和属性:


对于以上这些标签和属性:请使用样式代替。

HTML样式实例 - 背景颜色

background-color属性为元素定义了背景颜色:

<html>

<body style="background-color:yellow">
<h2 style="background-color:red">This is a heading</h2>
<p style="background-color:green">This is a paragraph.</p>
</body>

</html>

style属性淘汰了“旧的“bgcolor属性。

HTML样式实例 - 字体、颜色和尺寸

font-family、color以及font-size属性分别定义元素中文本的字体系列、颜色和字体的尺寸:

<html>

<body>
<h1 style="font-family:verdana">A heading</h1>
<p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p>
</body>

</html>

style属性淘汰了旧的<font>标签。

HTML样式实例 - 文本对齐

text-align 属性规定了元素中文本的水平对齐方式:

<html>

<body>
<h1 style="text-align:center">This is a heading</h1>
<p>The heading above is aligned to the center of this page.</p>
</body>

</html>

style属性淘汰了就的"align"属性

上一篇下一篇

猜你喜欢

热点阅读