css - 如何使多行省略号适用于 IE

标签 css

我正在尝试在 IE 中剪辑和处理多行的文本溢出。我正在使用以下 CSS。它适用于 Chrome 。但不适用于 IE。

 display: block;
display: -webkit-box;
max-width: 400px;
height: 50px;
margin: 0 auto;
font-size: 26px;
line-height: 1.4;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;

最佳答案

我为省略号使用自定义 jQuery 脚本,但删除 word-wrap: break-none; 或添加 word-wrap:normal 应该可以解决问题。参见 here .

这是我最喜欢的解决方案:

String.prototype.dotdotdot = function(len) {
    if(this.length > len){
        var temp = this.substr(0, len);
        temp = $.trim(temp);
        temp = temp + "...";
        return temp;
    }
    else
        return $.trim(this);
};

用法:

 title.dotdotdot(35);

Here@Alex 的 jQuery 自制插件解决方案你也可以使用:**

HTML/CSS

.ellipsis {
    white-space: nowrap;
    overflow: hidden;
}

.ellipsis.multiline {
    white-space: normal;
}

<div class="ellipsis" style="width: 100px; border: 1px solid black;">Lorem ipsum dolor sit amet, consectetur adipisicing elit</div>
<div class="ellipsis multiline" style="width: 100px; height: 40px; border: 1px solid black; margin-bottom: 100px">Lorem ipsum dolor sit amet, consectetur adipisicing elit</div>

jQuery

  <script type="text/javascript" src="/js/jquery.ellipsis.js"></script>
    <script type="text/javascript">
   $(document).ready(function(){
       //plugin usage
       $(".ellipsis").ellipsis();
   });
   (function($) {
        $.fn.ellipsis = function()
        {
            return this.each(function()
            {
                var el = $(this);

                if(el.css("overflow") == "hidden")
                {
                    var text = el.html();
                    var multiline = el.hasClass('multiline');
                    var t = $(this.cloneNode(true))
                        .hide()
                        .css('position', 'absolute')
                        .css('overflow', 'visible')
                        .width(multiline ? el.width() : 'auto')
                        .height(multiline ? 'auto' : el.height())
                        ;

                    el.after(t);

                    function height() { return t.height() > el.height(); };
                    function width() { return t.width() > el.width(); };

                    var func = multiline ? height : width;

                    while (text.length > 0 && func())
                    {
                        text = text.substr(0, text.length - 1);
                        t.html(text + "...");
                    }

                    el.html(t.html());
                    t.remove();
                }
            });
        };
    })(jQuery);

  </script>

关于css - 如何使多行省略号适用于 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40885598/

相关文章:

javascript - 如何在文本框中插入值时实现水平滚动条?

html - 即使使用 !important,字体颜色也不会改变

css - 在 Firefox 60 或更早版本中为 SVG 剪辑路径设置动画时出现随机方 block

html - 由于 div 的高度,页面没有从顶部开始

html - 如何对齐多个 float 元素

html - 用css绘制1/2或1/4等宽线宽圆线

javascript - 如何在断开连接的环境中使用 font-awesome?

html - 在所有页面上显示边栏上的编辑

c# - 如何设置 ASP :Menu with CSS 的样式

css - 使用溢出 :auto on a container to contain long paragraphs of text