简体   繁体   English

将半透明的div放在highcharts图上

[英]putting a semi-transparent div over a highcharts graph

is it possible to put a div over a generated highcharts graph? 是否可以将div放在生成的highcharts图上? As in, a div with a transparent background that will have text in it for purely aesthetic purposes. 例如,具有透明背景的div出于纯美学目的将在其中包含文本。

Being able to select the chart isn't important -- just seeing it. 能够选择图表并不重要-只是看到它即可。

Doing what you want can be done in CSS alone. 可以仅在CSS中完成您想做的事情。

As was mentioned in a comment, you want to have a relative container, and then absolute position the elements within it. 正如评论中提到的,您想要一个relative容器,然后将元素absolute定位在其中。

HTML HTML

<div class="container">
    <canvas id="myCanvas"></canvas>
    <div class="overlayed"></div>
</div>

CSS CSS

.container {
    width: 150px;
    height: 150px;
    position: relative;
}
div.overlayed, canvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

I just used a sample canvas element to give an idea of where your chart would be. 我只是使用了一个示例canvas元素来了解图表的位置。

Here's a JSFiddle 这是一个JSFiddle

Add div positioned absolutely with higher z-index than Highcharts chart. 绝对添加具有比Highcharts图表更高的z-index位置的div。 See: http://jsfiddle.net/Ww5Tg/9/ 请参阅: http//jsfiddle.net/Ww5Tg/9/

<div class="over"></div>
<div id="container" style="height: 300px; width: 400px"></div>

And CSS: 和CSS:

.over {
    width: 400px;
    height: 300px;
    position: absolute;
    z-index: 100;
    border: 1px solid black;
    background-color: black;
    opacity: 0.2;    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM