Я хочу всплывающую подсказку над некоторыми левосторонними элементами. Я хочу, чтобы некоторые всплывающие подсказки были выровнены по левому краю их родного брата, а некоторые - по правому краю их всплывающих подсказок. Я не могу понять, как выровнять элементы по правому краю относительно левого смещенного брата.
Ниже приведен код, который я пробовал. Я пытался заставить всплывающие подсказки на зеленом и синем сегментах выравниваться по правому краю цветных сегментов, а не по левому, но это не работает.
.textContent {
margin: 5px 0;
}
.bar {
box-sizing: border-box;
cursor: default;
height: 10px;
overflow: visible;
width: 100%;
}
.segment {
cursor: pointer;
display: inline-block;
float: left;
height: inherit;
position: relative;
width: 20%;
}
.section1 {
background-color: red;
}
.section2 {
background-color: orange;
}
.section3 {
background-color: yellow;
}
.section4 {
background-color: green;
}
.section5 {
background-color: blue;
}
.segment .tooltip {
background-color: #ffffff;
border: 1px solid #cc0000;
border-radius: 5px;
color: #000000;
float: left;
margin-top: 15px;
padding: 5px;
position: absolute;
text-align: center;
visibility: hidden;
z-index: 1;
}
.alignRightTooltip {
float: right;
}
.segment:hover .tooltip {
visibility: visible;
}
<DIV class="textContent">
Hover over bar to display tooltips
</DIV>
<DIV class="textContent">
The tooltips on the <SPAN style="color: green; font-weight: bold">green</SPAN> and <SPAN style="color: blue; font-weight: bold">blue</SPAN> bars should align to the right hand side of the segments
</DIV>
<DIV class="bar">
<DIV class="segment section1">
<SPAN class="tooltip">
section1
</SPAN>
</DIV>
<DIV class="segment section2">
<SPAN class="tooltip">
section2
</SPAN>
</DIV>
<DIV class="segment section3">
<SPAN class="tooltip">
section3
</SPAN>
</DIV>
<DIV class="segment section4">
<SPAN class="tooltip alignRightTooltip">
section4
</SPAN>
</DIV>
<DIV class="segment section5">
<SPAN class="tooltip alignRightTooltip">
section5
</SPAN>
</DIV>
</DIV>
Буду признателен за любые отзывы, не знаю, что я делаю не так.
Спасибо!