官术网_书友最值得收藏!

Adding some CSS classes to style the bars and text elements

When we added the rect elements, we added a female class attribute for the girls' names, and a male one for the boys' names and we've also set the style of our text elements to label. In our CSS file, we can now define colors and other styles based on these classes:

.male { 
fill: steelblue;
}

.female {
fill: hotpink;
}

.label {
fill: black;
font: 10px sans-serif;
text-anchor: end;
}

With these CSS properties, we set the fill color of our rectangles. The elements with the male class will be filled steelblue and the elements with the female class will be filled hotpink. We also change how the elements with the .label class are rendered. For these elements, we change the font and the text-anchor. The text-anchor, especially, is important here, since it makes sure that the text element's right side is positioned at the x and y value, instead of the left side. The effect is that the text element is nicely aligned at the end of our bars.

主站蜘蛛池模板: 横山县| 安达市| 太仆寺旗| 和硕县| 绥棱县| 伊金霍洛旗| 普定县| 乌兰察布市| 长岛县| 木兰县| 民丰县| 理塘县| 诸城市| 元朗区| 东光县| 德庆县| 房山区| 惠来县| 赞皇县| 沂源县| 伊川县| 阜新| 炉霍县| 千阳县| 宝清县| 桦甸市| 岚皋县| 兰溪市| 邛崃市| 鱼台县| 东台市| 肥城市| 瑞昌市| 靖远县| 嘉义县| 兴文县| 芒康县| 甘洛县| 翁源县| 南江县| 江津市|