实例 在 HTML 文档中使用 style 属性:This is a header This is a paragraph.Salin selepas log masuk定义和用法style 属性规定元素的行内样式(inline style)style 属性将覆盖任何全局的样式设定,例如在 标签或在外部样式表中规定的样式。</p><p style="margin: 0px; padding: 0px; border: 0px; font-size: 18px; color: rgb(63, 63, 63); font-family: 微软雅黑; white-space: normal; background-color: rgb(253, 252, 248);">支持</p><p>W3C: "W3C" 列指示 W3C 的 HTML/XHTML 推荐标准中是否定义了该属性。</p><table><tbody><tr class="firstRow"><td width="72" valign="top" style="word-break: break-all;">IE</td><td width="83" valign="top" style="word-break: break-all;">Firefox</td><td width="81" valign="top" style="word-break: break-all;">Opera</td><td width="83" valign="top" style="word-break: break-all;">Safari</td><td width="85" valign="top" style="word-break: break-all;">W3C</td></tr><tr><td width="72" valign="top" style="word-break: break-all;">YES</td><td width="83" valign="top" style="word-break: break-all;">YES</td><td width="81" valign="top" style="word-break: break-all;">YES</td><td width="83" valign="top" style="word-break: break-all;">YES</td><td width="85" valign="top" style="word-break: break-all;">YES</td></tr></tbody></table><p style="margin: 0px; padding: 0px; border: 0px; font-size: 18px; color: rgb(63, 63, 63); font-family: 微软雅黑; white-space: normal; background-color: rgb(253, 252, 248);">语法</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false"><element style="value"></pre><div class="contentsignin">Salin selepas log masuk</div></div><p style="margin: 25px 0px 0px; padding: 0px; border: 0px; font-size: 16px; color: rgb(0, 0, 0); font-family: PingFangSC-Regular, Verdana, Arial, 微软雅黑, 宋体; white-space: normal; background-color: rgb(253, 252, 248);">属性</p><table><tbody><tr class="firstRow"><td width="108" valign="top" style="word-break: break-all;">值</td><td width="1001" valign="top" style="word-break: break-all;">描述</td></tr><tr><td width="108" valign="top" style="word-break: break-all;">style_definition</td><td width="1001" valign="top" style="word-break: break-all;">一个或多个由分号分隔的 CSS 属性和值。</td></tr></tbody></table><p>以下是几个style属性的实例:</p><p>使用style属性改变背景颜色(bgcolor作用)</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false"><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></pre><div class="contentsignin">Salin selepas log masuk</div></div><p>style属性淘汰了旧的"bgcolor"属性。</p><p>使用style属性设置颜色、字体和尺寸</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false">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></pre><div class="contentsignin">Salin selepas log masuk</div></div><p>style属性淘汰了旧的<font>标签。</p><p>style属性设置文本对其方式</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false">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></pre><div class="contentsignin">Salin selepas log masuk</div></div><p>style属性淘汰了align属性。</p>