我在使用d3库时遇到了一些问题,因为我是新手。我使用了渐变example,将线性渐变插入到页脚div元素中。
#footer {
position: absolute;
z-index: 10;
bottom: 10px;
left: 50%;
width: 300px;
margin-left: -150px;
height: 20px;
border: 2px solid black;
background: rgba(12, 12, 12, 0.8);
color: #eee;
}
var svg = d3.select("footer")
.append("svg:svg")
.attr("width", 300)//canvasWidth)
.attr("height", 20);
svg.append("rect")
.attr("width", 300)
.attr("height", 20)
.style("fill", "url(#linear-gradient)");
var defs = svg.append("defs");
var linearGradient = defs.append("linearGradient")
.attr("id", "linear-gradient");
linearGradient.append("stop")
.attr("offset", "0%")
.attr("stop-color", "#ffa474");
linearGradient.append("stop")
.attr("offset", "100%")
.attr("stop-color", "#8b0000");
如何在渐变条的两侧插入文本"a"和"b",使文本位于条内并与左右两侧对齐,同时出现在颜色上方?我尝试在div元素中添加文本,但这只会“推开”渐变条。