*编辑添加js。
我正在尝试在我的工具提示中使用省略号但是当我添加溢出:隐藏时,箭头消失。我已经尝试了一些东西,比如overflow-y:可见overflow-x:隐藏,但这并不起作用。我在下面发布了css,工具提示在JS中用div" tooltip"调用。我感谢任何帮助。谢谢。 //唯一的html是在调用工具提示时,它是rel =" tooltip"。我将添加JS。
#tooltip
{
text-align: center;
color: #fff;
background: #0a3d54;
font-size: 13px;
position: absolute;
z-index: 100;
padding: 15px;
padding: 11px 16px 11px 16px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
#tooltip:after /* triangle decoration */
{
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #0a3d54;
content: '';
position: absolute;
left: 50%;
bottom: -10px;
margin-left: -10px;
}
#tooltip.top:after
{
border-top-color: transparent;
border-bottom: 10px solid #111;
top: -20px;
bottom: auto;
}
#tooltip.left:after
{
left: 10px;
margin: 0;
}
#tooltip.right:after
{
right: 10px;
left: auto;
margin: 0;
}
// JS
<script>
$( function()
{
var targets = $( '[rel~=tooltip]' ),
target = false,
tooltip = false,
title = false;
targets.bind( 'mouseenter', function()
{
target = $( this );
tip = target.attr( 'title' );
tooltip = $( '<div id="tooltip"><div id="test">r</div></div>' );
if( !tip || tip == '' )
return false;
target.removeAttr( 'title' );
tooltip.css( 'opacity', 0 )
.html( tip )
.appendTo( 'body' );
var init_tooltip = function()
{
if( $( window ).width() < tooltip.outerWidth() * 1.5 )
tooltip.css( 'max-width', $( window ).width() / 2 );
else
tooltip.css( 'max-width', 340 );
var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ),
pos_top = target.offset().top - tooltip.outerHeight() - 20;
if( pos_left < 0 )
{
pos_left = target.offset().left + target.outerWidth() / 2 - 20;
tooltip.addClass( 'left' );
}
else
tooltip.removeClass( 'left' );
if( pos_left + tooltip.outerWidth() > $( window ).width() )
{
pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20;
tooltip.addClass( 'right' );
}
else
tooltip.removeClass( 'right' );
if( pos_top < 0 )
{
var pos_top = target.offset().top + target.outerHeight();
tooltip.addClass( 'top' );
}
else
tooltip.removeClass( 'top' );
tooltip.css( { left: pos_left, top: pos_top } )
.animate( { top: '+=10', opacity: 1 }, 50 );
};
init_tooltip();
$( window ).resize( init_tooltip );
var remove_tooltip = function()
{
tooltip.animate( { top: '-=10', opacity: 0 }, 50, function()
{
$( this ).remove();
});
target.attr( 'title', tip );
};
target.bind( 'mouseleave', remove_tooltip );
tooltip.bind( 'click', remove_tooltip );
});
});
答案 0 :(得分:0)
您发布的代码没有提及#test
,overflow: hidden
或text-overflow: ellipsis
,因此我们无法告知您的错误。
此示例有效。我已为id
es更改class
以继续重复使用,但您明白了这一点。
.tooltip {
background-color: #0a3d54;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
color: #fff;
font-size: 13px;
padding: 10px 15px;
position: absolute;
text-align: center;
width: 200px;
z-index: 100;
}
.tooltip:after {
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #0a3d54;
bottom: -10px;
content: '';
height: 0;
left: 50%;
margin-left: -10px;
position: absolute;
width: 0;
}
.tooltip .content {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
&#13;
<div class="tooltip">
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
</div>
&#13;