Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. CSS:层叠样式表
  3. CSS 参考
  4. 属性
  5. outline-color

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

View in EnglishAlways switch to English

outline-color

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月.

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

尝试一下

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>  <div>    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-widthoutline-color会更方便。

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

语法

css
/* <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

反色,用于确认轮廓的显示。注意不是所有浏览器都支持该属性,若不则该属性无效。

形式语法

outline-color =
auto|
<'border-top-color'>

<border-top-color> =
<color>|
<image-1D>

<image-1D> =
<stripes()>

<stripes()> =
stripes(<color-stripe>#)

<color-stripe> =
<color>&&
[<length-percentage>|<flex>]?

<length-percentage> =
<length>|
<percentage>

示例

HTML

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

CSS

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

Accessibility concerns

Customfocus styles commonly involve making adjustments to theoutline 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 currentWeb 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 andbold or larger, or 24px or larger.

规范

Specification
CSS Basic User Interface Module Level 4
# outline-color
初始值auto
适用元素所有元素
是否是继承属性
计算值For the keywordauto, the computed value iscurrentcolor. For the color value, if the value is translucent, the computed value will be thergba() corresponding one. If it isn't, it will be thergb() corresponding one. Thetransparent keyword maps torgba(0,0,0,0).
动画类型acolor

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp