此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

style

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

style 全局属性包含应用到元素的 CSS 样式声明。要注意样式最好定义在单独的文件中。这个属性以及 <style> 元素的主要目的是快速装饰,例如用于测试目的。

尝试一下

<div style="background: #ffe7e8; border: 2px solid #e66465">
  <p style="margin: 15px; line-height: 1.5; text-align: center">
    Well, I am the slime from your video<br />
    Oozin' along on your livin' room floor.
  </p>
</div>

备注: 这个属性不能用于传递语义信息。即使所有样式都移除了,页面也应该保留正确语义。通常它不应用于隐藏不相关的信息;这应该使用 hidden 属性来实现。

规范

Specification
HTML
# the-style-attribute
CSS Style Attributes
# style-attribute

浏览器兼容性

参见