HTML中修改标签样式通常用style来实现。
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>
显示结果body标签下背景为黄色,h2标签下背景为红色,p标签下背景绿色。
这样就修改了背景有颜色,不同标签后添加表示在不同的位置的背景颜色。
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>
显示结果为:
A heading
A paragraph.
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>
这样h1标签下的内容居中对齐了。