Style et Couleur
Pour modifier le style et la couleur en SVG, on peut passer par des attributs ou par le css.
Définition : Remplissage
Couleur de remplissage
fill
ou
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<rect style="fill:red" x="50" y="20" rx="20" ry="20" width="150" height="150" />
3
</svg>
<svg width="300" height="200"> <rect style="fill:red" x="50" y="20" rx="20" ry="20" width="150" height="150" /> </svg>
SVG - Style
Opacité
fill-opacity
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<rect fill="blue" x="140" y="40" width="110" height="110" />
3
<rect fill="red" fill-opacity=0.8 x="50" y="20" width="150" height="150" />
4
</svg>
<svg width="300" height="200"> <rect fill="blue" x="140" y="40" width="110" height="110" /> <rect fill="red" fill-opacity=0.8 x="50" y="20" width="150" height="150" /> </svg>
ou
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<rect style="fill:blue" x="140" y="40" width="110" height="110" />
3
<rect style="fill:red;fill-opacity:0.8" x="50" y="20" width="150" height="150" />
4
</svg>
<svg width="300" height="200"> <rect style="fill:blue" x="140" y="40" width="110" height="110" /> <rect style="fill:red;fill-opacity:0.8" x="50" y="20" width="150" height="150" /> </svg>
SVG - Style
Définition : Bordure
Couleur de bordure
stroke
SVG - Style
Épaisseur de bordure
stroke-width
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<rect stroke-width=10 stroke='red' fill='none' x="50" y="20" width="150" height="150" />
3
</svg>
<svg width="300" height="200"> <rect stroke-width=10 stroke='red' fill='none' x="50" y="20" width="150" height="150" /> </svg>
SVG - Style
Opacité
stroke-opacity
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<rect fill="blue" x="140" y="40" width="110" height="110" />
3
<rect stroke-opacity=0.5 stroke-width=10 stroke='red' fill='none' x="50" y="20" width="150" height="150" />
4
</svg>
<svg width="300" height="200"> <rect fill="blue" x="140" y="40" width="110" height="110" /> <rect stroke-opacity=0.5 stroke-width=10 stroke='red' fill='none' x="50" y="20" width="150" height="150" /> </svg>
SVG - Style
Forme de fin de ligne
stroke-linecap (butt, square, round)
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<line stroke-linecap="butt" stroke-width="10" stroke="black" x1="20" y1="20" x2="280" y2="20" />
3
<line stroke-linecap="square" stroke-width="10" stroke="black" x1="20" y1="70" x2="280" y2="70" />
4
<line stroke-linecap="round" stroke-width="10" stroke="black" x1="20" y1="120" x2="280" y2="120" />
5
</svg>
<svg width="300" height="200"> <line stroke-linecap="butt" stroke-width="10" stroke="black" x1="20" y1="20" x2="280" y2="20" /> <line stroke-linecap="square" stroke-width="10" stroke="black" x1="20" y1="70" x2="280" y2="70" /> <line stroke-linecap="round" stroke-width="10" stroke="black" x1="20" y1="120" x2="280" y2="120" /> </svg>
SVG - Style
Jonction des lignes
stroke-linejoin (mitter, round, bevel)
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<polyline stroke-linejoin="mitter" stroke-width="20" stroke="black" fill="none" points="20,100 150,20 280,100" />
3
<polyline stroke-linejoin="round" stroke-width="20" stroke="black" fill="none" points="20,140 150,60 280,140" />
4
<polyline stroke-linejoin="bevel" stroke-width="20" stroke="black" fill="none" points="20,180 150,100 280,180" />
5
</svg>
<svg width="300" height="200"> <polyline stroke-linejoin="mitter" stroke-width="20" stroke="black" fill="none" points="20,100 150,20 280,100" /> <polyline stroke-linejoin="round" stroke-width="20" stroke="black" fill="none" points="20,140 150,60 280,140" /> <polyline stroke-linejoin="bevel" stroke-width="20" stroke="black" fill="none" points="20,180 150,100 280,180" /> </svg>
SVG - Style
style pointillés
stroke-dasharray (trait, espace)
CTRL+C pour copier, CTRL+V pour coller
1
<svg width="300" height="200">
2
<line stroke-dasharray="5,10" stroke-width="5" stroke="black" x1="20" y1="20" x2="280" y2="20" />
3
<line stroke-dasharray="5,10,15" stroke-width="5" stroke="black" x1="20" y1="70" x2="280" y2="70" />
4
<line stroke-dasharray="5,10,15,20" stroke-width="5" stroke="black" x1="20" y1="120" x2="280" y2="120" />
5
</svg>
<svg width="300" height="200"> <line stroke-dasharray="5,10" stroke-width="5" stroke="black" x1="20" y1="20" x2="280" y2="20" /> <line stroke-dasharray="5,10,15" stroke-width="5" stroke="black" x1="20" y1="70" x2="280" y2="70" /> <line stroke-dasharray="5,10,15,20" stroke-width="5" stroke="black" x1="20" y1="120" x2="280" y2="120" /> </svg>
SVG - Style