Outline ng CSS

此元素拥有黑色边框和蓝色轮廓,宽度为 10px。

Outline ng CSS

轮廓是在元素周围绘制的一条线,在边框之外,以凸显元素。

CSS 拥有如下轮廓属性:

  • outline-style
  • outline-color
  • outline-width
  • outline-offset
  • outline

Note:轮廓与边框不同!不同之处在于:轮廓是在元素边框之外绘制的,并且可能与其他内容重叠。同样,轮廓也不是元素尺寸的一部分;元素的总宽度和高度不受轮廓线宽度的影响。

CSS 轮廓样式

outline-style 属性指定轮廓的样式,并可设置如下值:

  • dotted - 定义点状的轮廓。
  • dashed - 定义虚线的轮廓。
  • solid - 定义实线的轮廓。
  • double - 定义双线的轮廓。
  • groove - 定义 3D 凹槽轮廓。
  • ridge - 定义 3D 凸槽轮廓。
  • inset - 定义 3D 凹边轮廓。
  • outset - 定义 3D 凸边轮廓。
  • none - 定义无轮廓。
  • hidden - 定义隐藏的轮廓。

下例展示了不同的 outline-style 值:

实例

演示不同的轮廓样式:

p.dotted {outline-style: dotted;}
p.dashed {outline-style: dashed;}
p.solid {outline-style: solid;}
p.double {outline-style: double;}
p.groove {outline-style: groove;}
p.ridge {outline-style: ridge;}
p.inset {outline-style: inset;}
p.outset {outline-style: outset;}

Result:

Dashed Outline.

Dotted Outline.

Solid Outline.

Dashed Outline.

3D Ridge Outline. This effect depends on the outline-color value.

3D Groove Outline. This effect depends on the outline-color value.

3D Emboss Outline. This effect depends on the outline-color value.

3D Bevel Outline. This effect depends on the outline-color value.

Try It Yourself

Note:Unless set outline-style Properties, otherwise other outline properties (which will be detailed in the next chapter) will not have any effect!