stroke

CSS stroke Property

The stroke property paints along the outline of the given graphical element.

The fill and stroke properties specify the paint used to render the interior and the stroke around shapes and text.

You can find web colors in the HTML colors section.

The presentation attribute will be overridden: e.g. <path stroke="#1c87c9" … />, it will be overridden. The inline style won’t be overridden: e.g. <path style=“stroke: #1c87c9;” … />.

The stroke property can be used as a CSS property as a presentation attribute. It can be applied to any element but can have an effect only on the following elements: <altGlyph>, <circle>, <ellipse>, <line>, <path>, <polygon>, <polyline>, <rect>, <text> ,<textPath>, <tref>, and <tspan>.

类目类目
Initial Valuenone
Applies toShapes and text content elements.
InheritedYes.
AnimatableNo.
VersionSVG 1.1 Specification
DOM SyntaxObject.stroke = “#1c87c9”;

Syntax

Syntax

stroke: color | url | none | context-fill | context-stroke | initial | inherit;

Example of the stroke property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Stroke property example</h2>
    <svg height="100" width="500">
      <g fill="none">
        <path stroke="#8ebf42" d="M5 20 l215 0" />
        <path stroke="#1c87c9" d="M5 40 l215 0" />
        <path stroke="#666666" d="M5 60 l215 0" />
      </g>
    </svg>
  </body>
</html>

Result

Example of the stroke property with the <svg> tag:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <h2>Stroke property example</h2>
    <svg viewBox="5 5 100 100">
      <style>
        path {
          fill: none;
          stroke-width: 3px;
          marker: url(#diamond);
        }
      </style>
      <path d="M 10,50 v -20 h 40 v -20" stroke="#666" />
      <path d="M 30,70 v -20 h 40 v -20" stroke="#8ebf42" />
      <path d="M 50,90 v -20 h 40 v -20" stroke="#1c87c9" />
      <marker id="diamond" markerWidth="12" markerHeight="12" refX="6" refY="6" markerUnits="userSpaceOnUse">
        <circle cx="6" cy="6" r="3" fill="#000" stroke="#ccc" stroke-width="1,5" />
      </marker>
    </svg>
  </body>
</html>

Values

Values

ValueDescription
noneNo paint is applied.
colorSets a solid color. Color names, hexadecimal color codes, rgb(), rgba(), hsl(), hsla() can be used.
urlA URL reference to a paint server element defining a paint server.
context-fillUses the value of fill from a context element.
context-strokeUses the value of stroke from a context element.
initialMakes the property use its default value.
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部