Disable underline for lowercase characters: g q p j y?

前端 未结 7 2277
清歌不尽
清歌不尽 2020-12-01 01:26

Sometimes you don\'t want an underline blindly cutting through an underlined page title!
Is there a way to automatically elegantly disable underline for

7条回答
  •  难免孤独
    2020-12-01 02:18

    This solution uses jQuery to automaticaly wrap the letters to underline in a tag.

    DEMO

    As parents with text-decoration:underline "override" children with text-decoration:none; (see here). The technique is to wrap only the targeted letters (the ones to underline) with a and apply text-decoration:underline; to that class.

    Output :

    no underline on selected characters with jQuery

    Signs that will not be underlined :

    g  j  p  q  y  Q  @  {  _  (  )  [  |  ]  }  ;  ,  §  µ  ç  /
    

    HTML :

    George quietely jumped!

    CSS :

    .underline {
        text-decoration:underline;
    }
    

    jQuery :

    $('.title').each(function () {
        var s = '',
            decoded;
        $(this).prop('innerHTML', function (_, html) {
            s += html.replace(/&/g, '&').replace(/(g|j|p|q|y|Q|@|{|_|\(|\)|\[|\||\]|}|;|,|§|µ|ç|\/)/g, '$1');
            s += ''
            $(this).html(s);
        });
    });
    

提交回复
热议问题