HTML教程-HTML Style

HTML样式用于更改或添加现有HTML元素的样式。每个HTML元素都有默认样式,例如白色背景和黑色文本颜色。
style
属性可用于任何HTML标签,以应用样式。要使用style
属性应用样式,您应该对CSS属性有基本了解,例如color
、background-color
、text-align
、font-family
、font-size
等。
style
属性的语法如下:
style="property:value"
HTML样式 color
color
属性用于定义文本颜色。
让我们通过CSS的color
属性来演示使用style
属性为HTML标签添加样式的简单示例:
<h3 style="color:green">This is Green Color</h3>
<h3 style="color:red">This is Red Color</h3>
输出:
This is Green Color
This is Red Color
HTML样式 background-color
background-color
属性用于定义HTML标签的背景颜色。
让我们通过CSS的background-color
属性来演示为HTML标签添加样式的示例:
<h3 style="background-color:yellow;">This is yellow background</h3>
<h3 style="background-color:red;color:white;">This is red background</h3>
输出:
This is yellow background
This is red background
HTML样式 font-family
font-family
属性用于指定HTML标签的字体系列。
让我们通过CSS的font-family
属性来演示为HTML标签添加样式的示例:
<h3 style="font-family:'times new roman'">This is times new roman font family</h3>
<p style="font-family:arial">This is arial font family</p>
输出:
This is times new roman font family
This is arial font family
HTML样式 font-size
font-size
属性用于定义HTML标签的文本大小。
让我们通过示例演示font-size
属性的使用:
<h3 style="font-size:200%">This is 200% h3 tag</h3>
<p style="font-size:200%">This is 200% p tag</p>
输出:
This is 200% h3 tag
This is 200% p tag
HTML样式 text-align
text-align
属性用于定义HTML元素的水平文本对齐方式。
让我们通过CSS的text-align
属性来演示为HTML标签添加样式的示例:
<h3 style="text-align:right;background-color:pink;">This text is located at the right side</h3>
<p style="text-align:center;background-color:pink;">This text is located at the center</p>
如果您想将标题居中或居左,可以使用"text-align:center"或"text-align:left"。
输出:
This text is located at the right side
This text is located at the center
HTML5不支持<center>
标签,该标签在较旧版本的HTML中受支持。
支持的浏览器:
元素 | ![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|---|
style属性 | 是 | 是 | 是 | 是 | 是 |
如果您想了解更多关于HTML样式的内容,可以阅读CSS教程。