CSS Text underlining too long when letter-spacing is applied?

前端 未结 7 1197
别那么骄傲
别那么骄傲 2020-11-29 11:00


Whenever letter-spacing is applied to something with an underline or a bottom border, it seems like the underline extends beyond the text on the right. Is

7条回答
  •  野性不改
    2020-11-29 11:55

    I wouldn't break text for SEO reasons, so I prefer to replace the underline with a fake one. CSS calc can help you with its width.

    a{
      text-decoration:none;
      letter-spacing:15px;
      color:red;
      display:inline-block;
    }
    
    a .underline{
      height:2px;
      background-color:red;
      width: calc(100% - 15px); /*minus letter spacing*/
    }
    Text
    

提交回复
热议问题