📅  最后修改于: 2023-12-03 15:20:24.354000             🧑  作者: Mango
<style>
ElementThe SVG <style>
element allows you to embed CSS styles directly into your SVG document. It is used to define styles for SVG elements, similar to how CSS is used to style HTML elements.
To use the <style>
element, you need to place it within the <svg>
root element of your SVG document. Here is an example of how to include the <style>
element in SVG:
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400">
<style>
/* CSS styles go here */
</style>
<!-- SVG content goes here -->
</svg>
Inside the <style>
element, you can write CSS rules that target specific SVG elements using their element name, class, or ID. You can also use other CSS selectors like attribute selectors and pseudo-classes.
Here are a few examples of how you can use the <style>
element in SVG:
<circle>
element using its class:.circle {
fill: red;
}
<circle class="circle" cx="50" cy="50" r="40" />
<rect>
element using its ID:#myRect {
stroke: blue;
stroke-width: 2;
}
<rect id="myRect" x="10" y="10" width="100" height="50" />
<g>
element:.group {
transform: translate(50, 50) rotate(45deg);
}
<g class="group">
<!-- SVG content goes here -->
</g>
The <style>
element supports a wide range of CSS properties that can be applied to SVG elements, including:
fill
, stroke
, stroke-width
)font-family
, font-size
, text-anchor
)translate
, rotate
, scale
)animation-name
, animation-duration
)For a complete list of supported properties and their descriptions, you can refer to the SVG specification.
There are a few limitations to keep in mind when using the <style>
element in SVG:
<style>
element.<style>
element.The <style>
element in SVG allows you to apply CSS styles to SVG elements, giving you control over their appearance and behavior. It offers a flexible and powerful way to create visually appealing and interactive SVG graphics.
For more information and examples, please refer to the MDN Web Docs on SVG <style>
.