我被卡住了。我想在使用d3創建的SVG圖表上添加一個html下拉菜單。目前,下拉菜單出現在圖表下方,但我希望下拉菜單顯示在圖表上的特定位置。d3下拉菜單SVG
我不清楚如果我的問題是瀏覽器呈現所有元素的順序,或者它只是一個CSS問題。
任何幫助,將不勝感激。
這裏是我的html:
<div class="chartArea">
<select class = "demoSelection"></select></div>
這裏是我的CSS:
.chartArea{
position: relative;}
.demoSelection {
position: absolute;
width: 250px;
top:400px;
left:250px;}
這裏就是我創建D3中的SVG元素:
var svg = d3.select("body").select(".chartArea")
.append("svg")
.attr("id","svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("class","chart");
我後來填充選擇框d3中的選項
d3.select(".demoSelection")
.append("option")
.attr("value",demoCounter)
.text(json.demos[demoCounter].title);
感謝您的代碼!事實證明,這是可能的,而且我的代碼已經失效了。在比較你的css元素樣式和我自己的chrome後,我發現我的.css類沒有被正確拾取。原來,我在SASS有一個嵌套問題。非常感謝! – AmericanCities