Edit line thickness of CSS 'underline' attribute

前端 未结 11 645
日久生厌
日久生厌 2020-12-02 07:35

Since you can underline any text in CSS like so:

h4 {
    text-decoration: underline;
}

How can you also then edit the \'line\' that is drawn

相关标签:
11条回答
  • 2020-12-02 08:19

    Thanks to the magic of new css options this is now possible natively:

    a {
      text-decoration: underline;
      text-decoration-thickness: 5px;
      text-decoration-skip-ink: auto;
      text-underline-offset: 3px;
    }
    

    As of yet support is relatively poor. But it'll land in other browsers than ff eventually.

    0 讨论(0)
  • 2020-12-02 08:20

    Another way to do this is using ":after" (pseudo-element) on the element you want to underline.

    h2{
      position:relative;
      display:inline-block;
      font-weight:700;
      font-family:arial,sans-serif;
      text-transform:uppercase;
      font-size:3em;
    }
    h2:after{
      content:"";
      position:absolute;
      left:0;
      bottom:0;
      right:0;
      margin:auto;
      background:#000;
      height:1px;
    
    }
    
    0 讨论(0)
  • 2020-12-02 08:21

    I will do something simple like :

    .thickness-underline {
        display: inline-block;
        text-decoration: none;
        border-bottom: 1px solid black;
        margin-bottom: -1px;
    }
    
    • You can use line-height or padding-bottom to set possition between them
    • You can use display: inline in some case

    Demo : http://jsfiddle.net/5580pqe8/

    CSS underline

    0 讨论(0)
  • 2020-12-02 08:22

    a {
      text-decoration: none;
      position: relative;
    }
    
    a.underline {
      text-decoration: underline;
    }
    
    a.shadow {
       box-shadow: inset 0 -4px 0 white, inset 0 -4.5px 0 blue;
    }
    <h1><a href="#" class="underline">Default: some text alpha gamma<br>the quick brown fox</a></h1>
    <p>Working:</p>
    <h1><a href="#" class="shadow">Using Shadow: some text alpha gamma<br>the quick brown fox<br>even works with<br>multiple lines</a></h1>
    <br>

    Final Solution: http://codepen.io/vikrant-icd/pen/gwNqoM

    a.shadow {
       box-shadow: inset 0 -4px 0 white, inset 0 -4.5px 0 blue;
    }
    
    0 讨论(0)
  • 2020-12-02 08:27

    My Solution : https://codepen.io/SOLESHOE/pen/QqJXYj

    {
        display: inline-block;
        border-bottom: 1px solid;
        padding-bottom: 0;
        line-height: 70%;
    }
    

    You can adjust underline position with line-height value, underline thickness and style with border-bottom.

    Beware to disable default underline behavior if you want to underline an href.

    0 讨论(0)
提交回复
热议问题