大网数据广告活动
Web 标准与前端开发

outline-color

· 52CE 我爱测

**`outline-color`** CSS 属性 被用于设置一个元素轮廓的颜色。

outline-color CSS 属性 被用于设置一个元素轮廓的颜色。

CSS Demo: outline-color

outline-color: red;
outline-color: #32a1ce;
outline-color: rgba(170, 50, 220, 0.6);
outline-color: hsla(60, 90%, 50%, 0.8);
outline-color: currentcolor;
<section class="default-example" id="default-example">
  <div class="transition-all" id="example-element">
    This is a box with an outline around it.
  </div>
</section>
#example-element {
  outline: 0.75em solid;
  padding: 0.75em;
  width: 80%;
  height: 100px;
}

大多时候使用outline而不是 outline-style, outline-width 和 outline-color会更方便。

元素轮廓是绘制于元素周围的一条线,位于border的外围,使元素突出。不像 border,轮廓在元素的 frame 外绘制并且可能与其他元素重叠。而 border 不会出现这种现象 (除非故意).

语法

/* <color> values */
outline-color: #f92525;
outline-color: rgb(30, 222, 121);
outline-color: blue;

/* Keyword value */
outline-color: invert;

/* Global values */
outline-color: inherit;
outline-color: initial;
outline-color: unset;

outline-color可用以下这些值。

值

  • <color>
    • : 轮廓颜色,规则同 <color>.
  • invert
    • : 反色,用于确认轮廓的显示。注意不是所有浏览器都支持该属性,若不则该属性无效。

形式语法

示例

HTML

<p>My outline is blue, as you can see.</p>

CSS

p {
  outline: 2px solid; /* Set the outline width and style */
  outline-color: #0000ff; /* Make the outline blue */
  margin: 5px;
}

示例

Accessibility concerns

Custom focus styles commonly involve making adjustments to the outline property. If the color of the outline is adjusted, it is important to ensure that the contrast ratio between it and the background the outline is placed over is high enough that people experiencing low vision conditions will be able to perceive it.

Color contrast ratio is determined by comparing the luminosity of the text and background color values. In order to meet current Web Content Accessibility Guidelines (WCAG), a ratio of 4.5:1 is required for text content and 3:1 for larger text such as headings. Large text is defined as 18.66px and bold or larger, or 24px or larger.

规范

浏览器兼容性

参见

  • <color> 数据类型
  • 其他与颜色有关的属性:color, background-color, border-color, text-decoration-color, text-emphasis-color, text-shadow, caret-color, 和column-rule-color
  • Applying color to HTML elements using CSS

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。