I found a helpful tooltip on this site:
I customized it to work with an input element:
<div class="tooltip">
<input type="text" placeholder="Name" name="dp_name">
<span>Full name asd as dasd as dasd</span>
</div>
Here is the CSS:
.tooltip {
position: relative;
display: inline;
}
.tooltip span {
position: absolute;
width: 120px;
color: #FFFFFF;
background: #327FBA;
min-height: 32px;
line-height: 16px;
text-align: center;
visibility: hidden;
border-radius: 5px;
font-size: 12px;
}
.tooltip span:after {
content: '';
position: absolute;
top: 50%;
right: 100%;
margin-top: -8px;
width: 0; height: 0;
border-right: 8px solid #327FBA;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
}
.tooltip:hover span {
visibility: visible;
opacity: 0.9;
left: 100%;
top: 50%;
margin-top: -16px;
margin-left: 15px;
z-index: 999;
}
The issue arises when the text exceeds the width of the tooltip, causing a line break and overflowing the background.
In my attempts to fix it by changing width:
to min-width:
in .tooltip span {}
, or using width: auto
, the tooltip either didn't expand correctly or became too narrow.
However, I did manage to contain the text vertically by replacing height
with min-height
.
Any suggestions on how I can restrict the text to a maximum width of 300px within the tooltip? (using max-width) It should then wrap onto a new line while maintaining vertical containment.
Thank you for your help!