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

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.

主站蜘蛛池模板: 南宁市| 桃江县| 阿合奇县| 大宁县| 河东区| 松原市| 阿克| 贵南县| 华坪县| 新昌县| 屏东市| 五指山市| 泰来县| 天水市| 隆子县| 长岭县| 获嘉县| 镇沅| 武川县| 姜堰市| 德阳市| 曲松县| 英超| 长丰县| 滁州市| 公主岭市| 同江市| 洮南市| 昌黎县| 厦门市| 安多县| 岳阳市| 深圳市| 宁阳县| 安化县| 仙游县| 栾城县| 盐池县| 鹤庆县| 普宁市| 余江县|