zoukankan      html  css  js  c++  java
  • css文字超出显示省略号

    单行的:

    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;

    多行的:

    word-break: break-all;
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;

     js判断文字是否超出显示...了,如果是,执行一些方法:

    jquery 判断文字是否超出div出现三个点的省略号

    有个需求,就是一个div宽度固定,但是文字可能会超出,超出出现三个点省略,然后鼠标划入的时候显示全部,不超出鼠标划入就不显示,这就意味着要判断文字是否超出了

    <html lang="en">
     <head>
      <title>Document</title>
     </head>
     <body>
    
        <div class="main-left">
            <span class="word fl">填报日期填报日期填报日期填报日期填报日期</span>
            <span>:</span>
    
            <span class="title">人填报人填报人填报人填报人</span>
        </div>
            <div class="main-right">
            <div class="layui-inline input-width-full">
                <input type="text" class="layui-input" placeholder="">
            </div>
        </div>
    
        <script>
    
            $(".main-left > .word").mouseenter(function (e) {
                var thisWidth = $(this).width(); // div 的宽度
                var wordWidth = $(this)[0].scrollWidth; // 先转为js对象; 文字的宽度
                if(wordWidth > thisWidth+5){ // 加5是为了让div宽度多一点,比文字不超出时多宽,因为文字不超出,那么宽度为div的宽度
                    $(this).siblings('span.title').html($(this).text()).show();
                }
                
            })
            $(".main-left > .word").mouseleave(function () {
                // layer.msg('显示')
                $(this).siblings('span.title').hide();
            })
        </script>
      
     </body>
    </html>
  • 相关阅读:
    sqlserver编程基本语法
    每日一记--技术小细节
    每日一记--jsp
    每日一记--session/servletContext
    每日一记--cookie
    每日一记--HashTable/HashMap/ConcurrentHashMap
    每日一记--Ajax(下)
    每日一记--Axjx
    每日一记--索引/过滤器
    每日一记--酱油日
  • 原文地址:https://www.cnblogs.com/sherryweb/p/12759807.html
Copyright © 2011-2022 走看看