I have created an SVG map for a WordPress website I am building.
I need help on adding a CSS only tooltip for my map. I want it to popup only by hovering the countries in class st0. and getting the information from the data-info of the path of each country in the SVG.
Here is my code- https://codepen.io/ohad-olshevsky/pen/bGbNOVW
Here is the tooltip (the top one) style I tried adding but failed.- https://www.w3schools.com/css/css_tooltip.asp
I am using Elementor pro plugin and adding this map using the HTML widget. This limits my use of JS and JQ, so I need the tooltip using only CSS.
Thank you for your help.
I tried using jquery and javascript but I don’t have enough experience on these and the elementor plugin don’t work well with these.
css-
#un-map-by-ohad {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.st0{fill:#ffFFFF;stroke:#262626;}
.st0{
transition-property: opacity;
transition-duration: .7s;
transition-timing-function: ease;
}
.st1{fill:#262626;stroke:#A8D3E8;stroke-width:5.5;}
.st0:hover {
fill:white;
opacity: 0.3;
stroke-width: 0px;
stroke: #476ebf;
stroke-opacity: o;
background-size: 70%;
transition-property: opacity;
transition-duration: .7s;
transition-timing-function: ease;
}
.st2{color:#262626;stroke:#FFFFFF;stroke-width:0.5;}
.st3{fill:#262626;stroke:#FFFFFF;stroke-width:0.5;stroke-opacity:0.9412;}
.st4{color:transparent;}
#info-box
{
display: none;
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
background-color: #ffffff;
border: 2px solid #476ebf;
border-radius: 5px;
padding: 5px;
font-color:white;
font-family: open sans;
}
HTML
<path id="es" data-info="<div>Spain</div><div>2.6%</div>" class="st0" d="M5036.5,4876c10,4.3,21.5,7.2,28.7,12.9c2.9,2.9,4.3,18.6,12.9,17.2c11.5-1.4,21.5-8.6,34.4-8.6"/>
2
Answers
Use
::after
psuedo element to display data attribute noticecontent
in.country::after
.If you what you, want is info to occur at same position for every country pay attention to lines following
position
property in.country::after
.To display prompts, you can use the SVG
<title> ... </title>
If you want to implement prompt output, for example, of some part of the map, then you need to wrap the
path
that draws this section with the group tag<g>
And place a double
<title> ...</title>
tag with explanatory text insidefor example: