HTML样式用于更改或添加现有HTML元素的样式。每个HTML元素都有默认样式,例如白色背景和黑色文本颜色。

style属性可用于任何HTML标签,以应用样式。要使用style属性应用样式,您应该对CSS属性有基本了解,例如colorbackground-colortext-alignfont-familyfont-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中受支持。

支持的浏览器:

元素chrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
style属性

如果您想了解更多关于HTML样式的内容,可以阅读CSS教程。

标签: html, HTML教程, HTML技术, HTML学习, HTML学习教程, HTML下载, HTML语言, HTML开发, HTML入门教程, HTML进阶教程, HTML面试题, HTML笔试题, HTML编程思想