编程语言
首页 > 编程语言> > javascript-如何将html文本放在画布浮动图表的顶部?

javascript-如何将html文本放在画布浮动图表的顶部?

作者:互联网

这是我的简单jsFiddle.我希望将HTML文本放置在浮动图表的顶部.或将浮点图放在背景中(取决于您的想法).

HTML:

<div id="wrapper">
  <h1>Place me on top please. How?!</h1>
  <div id="placeholder"></div>
</div>

CSS:

#wrapper { position:relative; }
h1 { z-index:100; color:blue; font-size:5em; margin:0; line-height:0.9em; }
#placeholder {
    width:500px;
    height:300px;
    position:absolute;
    top:0;
    left:0;
    z-index:1;
}

JS(其余请参阅jsFiddle):

$(document).ready(function(){
    chart = $.plot($("#placeholder"),data,options);
});

解决方法:

您应该添加位置:绝对;到您的CSS中的h1 …

Note: z-index only works on positioned elements (position:absolute,
position:relative, or position:fixed).

source of this quoted text

#wrapper { position:relative; }
h1 { z-index:100; color:blue; position: absolute; font-size:5em; margin:0; line-height:0.9em; }
#placeholder {
    width:500px;
    height:300px;
    position:absolute;
    top:0;
    left:0;
    z-index:1;
}

:::: JSFIDDLE ::::

标签:flot,z-index,css,javascript,jquery
来源: https://codeday.me/bug/20191029/1958165.html