I’m trying to make a tooltip, that pops up when hovered over, not wrap text when it is immediately able to. The tooltip functionality works perfectly, this question is purely related to text wrapping and width and such. Currently, the it wraps to the width of the longest word it contains, but I want it to reach the width of the viewport before wrapping text.
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<a class="tooltip">
Hover
<div class="tooltip tooltiptext">
Tooltip Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
</div>
</a>
2
Answers
Remove "position: relative;" and you get this css:
I would add a
width
to the div, so that you can control how much space it actually use.You can also remove the
display: inline-block
if you don’t want the div to go to the right