I have a problem in building something typically I am not a front-end developer so although trying several things I failed. The problem:
I have several sentences in a document, and each sentence has several words. Each of these words might be relevant. For instance a word might signal a place, time or something like that. What I want to achieve that if someone hovers over a verb in a sentence only the relevant words in that sentence get a color. The colors function as a sort of map to indicate what is what.
Tried so far:
In CSS I have tried to use something like a pseudo class. However, the problem is that if you use the pseudo class hover, only the elements (e.g. spans) after the verb change. I need every relevant word(or element probably) to change.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/contractinfo.css">
</head>
<body>
<div class = "sentence">
<span class = "word">The</span>
<span class = "agent">Party</span>
<span class = "verb" id = "verb">gives
<span class="actiontext">Action Text</span>
</span>
<span class = "word">1000</span>
<span class = "resource">Euro</span>
<span class = "word">.</span>
</div>
</body>
</html>
The CSS code I tried:
.sentence{
font: Helvetica;
}
.word{
display: inline-block;
margin-right: 4px;
padding: 3px;
}
.agent{
display: inline-block;
margin-right: 4px;
padding: 3px;
}
.resource{
display: inline-block;
margin-right: 4px;
padding: 3px;
}
/*text of the verb that is initially displayed */
.verb {
position: relative;
display: inline-block;
border-bottom: 1px dotted blue;
margin-right: 4px;
padding: 3px;
}
/*text of the action(s) that should be displayed once hovered*/
.verb .actiontext {
visibility: hidden;
width: 120px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}
.verb .actiontext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
.verb:hover .actiontext {
visibility: visible;
opacity: 1;
}
.verb:hover ~ .resource { background-color: yellow;
}
All help is much appreciated!