| 目次 |
|---|
|
・<svg>要素とCSS ・CSS3メソッド |
<svg>要素は、CSS(Cascading Style Sheets)は密接な関係を持っています。
各図形要素の線(stroke)や塗りつぶし(fill)など、スタイルを示す属性は、必要に応じてCSSで定義することができます。
<rect fill="red" stroke="blue" />
<rect style="fill:red;stroke:blue;" />
<svg id="svg0101" width="500" height="200">
<rect id="red_rect" class="blue-box" />
</svg>
<style>
svg {
background-color : silver;
}
rect {
stroke-width : 2px;
}
#red_rect {
fill : red;
}
.blue-box {
stroke : blue;
}
</style>
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
<svg>要素に対してCSS3プロパティが適用出来るものは少ないです。
しかし、半透明など一部のCSS3メソッドを適用することは可能です。
リスト1. rgba()の適用
<svg id="svg0201" width="500" height="200">
<circle cx="150" cy="100" r="80" class="stroke-r-a fill-b-a" />
<circle cx="250" cy="100" r="80" class="stroke-g-a fill-r-a" />
<circle cx="350" cy="100" r="80" class="stroke-b-a fill-g-a" />
</svg>
<style>
.stroke-r-a {
stroke : rgba(255,0,0,0.8);
}
.stroke-g-a {
stroke : rgba(0,255,0,0.5);
}
.stroke-b-a {
stroke : rgba(0,0,255,0.3);
}
.fill-r-a {
fill : rgba(255,0,0,0.3);
}
.fill-g-a {
fill : rgba(0,255,0,0.5);
}
.fill-b-a {
fill : rgba(0,0,255,0.8);
}
</style>
コーディング例