首页  >  文章  >  web前端  >  html规定元素的行内样式(inline style)的属性style

html规定元素的行内样式(inline style)的属性style

黄舟
黄舟原创
2017-11-03 13:43:108836浏览

实例

在 HTML 文档中使用 style 属性:

<h1 style="color:blue; text-align:center">This is a header</h1>
<p style="color:red">This is a paragraph.</p>

定义和用法

style 属性规定元素的行内样式(inline style)

style 属性将覆盖任何全局的样式设定,例如在 c9ccee2e6ea535a969eb3f532ad9fe89 标签或在外部样式表中规定的样式。

支持

W3C: "W3C" 列指示 W3C 的 HTML/XHTML 推荐标准中是否定义了该属性。

IE Firefox Opera Safari W3C
YES YES YES YES YES

语法

<element style="value">

属性

描述
style_definition 一个或多个由分号分隔的 CSS 属性和值。

以下是几个style属性的实例:

使用style属性改变背景颜色(bgcolor作用)

<span style="font-size: 12pt;"><html>
<body style = "
<h1 stye = "background-color:red>This is a Heading</h1>
<p style = "background-color:green>This is a Paragraph</p>
</body>
</html></span>

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

使用style属性设置颜色、字体和尺寸

1 <html>
2 <body>
3 <h1 style = "font-family:verdana">A Heading</h1>
4 <p style = "font-family:arial;color:red;font-size:20px;">A Paragraph</p>
5 </body>
6 </html>

style属性淘汰了旧的240cb830ca84ebaabbd07850110b414d标签。

style属性设置文本对其方式

1 <html>
2 <body>
3 <h1 style = "text-align:center;">A Heading</h1>
4 <p>The heading above is aligned to the center of the page</p>
5 </body>
6 </html>

style属性淘汰了align属性。

以上是html规定元素的行内样式(inline style)的属性style 的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn