HTML 的 style 属性:
style 属性的作用:
提供了一种改变所有 HTML 元素的样式的通用方法。
样式是 HTML 4 引入的,它是一种新的首选的改变 HTML 元素样式的方式。通过 HTML 样式,能够通过使用 style 属性直接将样式添加到 HTML 元素,或者间接地在独立的样式表中(CSS 文件)进行定义。
格式:<标签 style =”属性”></标签>
改变盒子大小边框字体颜色属性尺寸:
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
</head>
<body>
<div style=”border: 1px solid #000;width: 200px;height: 200px;”>
<p style=”font-family: ‘Courier New’, Courier, monospace;font-size: 14px;color: #000; text-align: center;”>style</p>
</div>
</body>
</html>
效果
设置背景颜色:
<div style=”background: lightblue; margin: 10px auto;border: 1px solid #000;width: 200px;height: 200px;”>
HTML 样式实例 – 文本对齐
text-align 属性规定了元素中文本的水平对齐方式:
<body>
<div style=”width: 200px;height: 200px;background:blanchedalmond;text-align: center;”>对齐</div>
</body>
、
应避免使用以下属性和标签:
属性 | 描述 |
bgcolor | 定义背景颜色 |
align | 定义文本对齐方式 |
color | 定义颜色 |
标签 | 描述 |
<s>和<strike> | 定义删除文本 |
<font>和<basefont> | 定义html文本字体 |
<center></center> | 定义居中 |
<u></u> | 定义下划线 |
以上可以用样式代替!
是小白,有什么不足欢迎多多批评和补充!