实例
在 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 属性将覆盖任何全局的样式设定,例如在
支持
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属性淘汰了旧的标签。
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中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号