2017-03-17 39 views
0

我们有一个提示框,其CSS低于:工具提示框,看起来怪怪当输入文本太长

.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; 
} 

通常情况下,它工作正常。如图所示:

enter image description here

然而,当文本变得很长,它看起来如下:

enter image description here

我不太清楚这是怎么引起的,但我假设它是因为文本太长,超出了原始tooltip.png的最大长度。但问题是我该如何解决这个问题?

谢谢。

+0

添加一个工作演示,了解HTML结构 – aje

+0

你可以包括你的HTML以及 –

+0

添加'溢出-Y:滚动;'如果你不想要的布局被打破。这可能是你使用的绝对位置,它在'px'中。 – user3771102

回答

1

我会建议使用纯CSS与此,不要乱用图像拼接/精灵。这是一个相当古老的技术。

.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>

+0

谢谢你。我已经调整了这一点,它非常有效。我们能否让这个小三角形变成黑色而不是白色?我已经尝试了几件事,但没有运气。 –

+0

无需担心这一点。我想这需要更复杂的html结构,然后才能实现。谢谢你。 –

+0

我编辑了我的帖子,将箭头更改为黑色,但您认为会有更多的HTML元素需要添加以使其完全像您的示例一样正确。由于CSS限制,我提供的是最接近的,因此无法为边框三角形添加阴影。 – l3fty

相关问题