outline CSS shorthand property set all the outline properties in a single declaration.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

组成特性

此特性是下列 CSS 特性的简写:

句法

/* style */
outline: solid;
/* color | style */
outline: #f66 dashed;
/* style | width */
outline: inset thick;
/* color | style | width */
outline: green solid 3px;
/* Global values */
outline: inherit;
outline: initial;
outline: unset;
					

outline property may be specified using one, two, or three of the values listed below. The order of the values does not matter.

注意: The outline will be invisible for many elements if its style is not defined. This is because the style defaults to none . A notable exception is input elements, which are given default styling by browsers.

<'outline-color'>
Sets the color of the outline. Defaults to currentcolor if absent. See outline-color .
<'outline-style'>
Sets the style of the outline. Defaults to none if absent. See outline-style .
<'outline-width'>
Sets the thickness of the outline. Defaults to medium if absent. See outline-width .

描述

Borders and outlines are very similar. However, outlines differ from borders in the following ways:

  • Outlines never take up space, as they are drawn outside of an element's content.
  • According to the spec, outlines don't have to be rectangular, although they usually are.

As with all shorthand properties, any omitted sub-values will be set to their initial value .

可访问性关注

Assigning outline a value of 0 or none will remove the browser's default focus style. If an element can be interacted with it must have a visible focus indicator. Provide obvious focus styling if the default focus style is removed.

形式定义

初始值 as each of the properties of the shorthand:
适用于 所有元素
继承 no
计算值 as each of the properties of the shorthand:
  • outline-color : For the keyword invert , the computed value is invert . For the color value, if the value is translucent, the computed value will be the rgba() corresponding one. If it isn't, it will be the rgb() corresponding one. The transparent keyword maps to rgba(0,0,0,0) .
  • outline-width : an absolute length; if the keyword none is specified, the computed value is 0
  • outline-style :如指定
动画类型 as each of the properties of the shorthand:

形式句法

[ <'outline-color'> || <'outline-style'> || <'outline-width'> ]
					

范例

Using outline to set a focus style

HTML

<a href="#">This link has a special focus style.</a>
					

CSS

a {
  border: 1px solid;
  border-radius: 3px;
  display: inline-block;
  margin: 10px;
  padding: 5px;
}
a:focus {
  outline: 4px dotted #e73;
  outline-offset: 4px;
  background: #ffa;
}
					

结果

规范

规范 状态 注释
CSS Basic User Interface Module Level 3
The definition of 'outline' in that specification.
推荐 无变化。
CSS Level 2 (Revision 1)
The definition of 'outline' in that specification.
推荐 初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
outline Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1.5 注意事项
完整支持 1.5 注意事项
注意事项 Firefox includes absolutely positioned elements inside the outline (see bug 687311 ).
不支持 1 — 3.6 Prefixed
Prefixed Implemented with the vendor prefix: -moz-
IE 完整支持 8 Opera 完整支持 7 Safari 完整支持 1.2 WebView Android 完整支持 1 Chrome Android 完整支持 18 Firefox Android 完整支持 4 Opera Android 完整支持 10.1 Safari iOS 完整支持 3.1 Samsung Internet Android 完整支持 1.0

图例

完整支持

完整支持

见实现注意事项。

见实现注意事项。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

元数据

  • 最后修改: