Lance Shi
Lance Shi

Reputation: 1187

Tooltip box looks weird When input text is too long

We have a tooltip box whose css are below:

.radioButton-tooltip
 {
    position: absolute;
    width: 205px;
    padding: 5px 20px 5px 35px;
    left: 100%;
    margin-left: -17px;
    font-size: 13px;
    background: url(images/tooltip.png) 0 center no-repeat;
    color: #ffffff;
    display: none;
    text-align:left;
    z-index:100;

}
 .radioButton-tooltip:before, .radioButton-tooltip:after, .radioButton-tooltip .before, .radioButton-tooltip .after 
 {
    content: '';
    background-image: url(images/tooltip.png);
    background-repeat: no-repeat;
    height: 10px;
    width: 100%;
    display: block;
    position: absolute;
    left: 0;
    z-index:100;
}

.radioButton-tooltip:before,  .radioButton-tooltip .before
{
    background-position: 0 top;
    top: -10px;
    z-index:100;
}

.radioButton-tooltip:after, .radioButton-tooltip .after
{
    background-position: 0 bottom;
    bottom: -10px;
    z-index:100;
}

Normally, it works fine. As shown:

enter image description here

However, when the text becomes very long, it looks as below:

enter image description here

I am not quite sure how this is caused but I am assuming it is because the text is too long which exceeds the original tooltip.png's maximum length. But the question is how should I fix that?

Thanks.

Upvotes: 0

Views: 375

Answers (1)

l3fty
l3fty

Reputation: 582

I would suggest using pure CSS with this and don't mess with using image splicing/sprites. That's quite an old technique.

.tool-tip {
  left: 40px;
  position: relative;
  background: rgba(0,0,0,0.75);
  border-radius: 10px;
  border: 3px solid #fff;
  box-shadow: 0 0 3px 1px rgba(0,0,0,0.3);
  padding: 15px;
  max-width: 250px;
  color: #fff;
  font: normal 100% Arial, sans-serif;
}
.tool-tip:after, .tool-tip:before {
  position: absolute;
  left: -15px;
  top: calc(50% - 15px);
  content: "";
  display: block;
  width: 0;
  height: 0;
  width: 0; 
  height: 0; 
}
.tool-tip:after {
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
  border-right: 15px solid #444;
}
/*.tool-tip:before {
  top: calc(50% - 18px);
  left: -21px;
  border-top: 18px solid transparent;
  border-bottom: 18px solid transparent;
  border-right: 18px solid #fff;
}*/

.tool-tip:first-child {
  margin-bottom: 25px;
}
<div class="tool-tip">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu lorem sit amet erat pellentesque gravida. Cras scelerisque, lorem a feugiat blandit, risus eros interdum orci, non aliquet dui ex a ipsum. 
</div>

<div class="tool-tip">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>

Upvotes: 1

Related Questions