text-decoration: underline vs border-bottom

后端 未结 7 1811
后悔当初
后悔当初 2021-02-13 04:04

What is the difference to use {text-decoration: underline} and {border-bottom: ...}?

which is easy to style and cross browser compatible?

7条回答
  •  不思量自难忘°
    2021-02-13 04:40

    As Ignacio said, border-bottom will put the line at the bottom of the containing box, whereas text-decoration:underline will actually underline the text. This becomes an important distinction for multi-line strings.

    I am a single line and will look similar for both methods
    ---------------------------------------------------------
    

    would probably render the same for both styles, but you'll get the following for multi-line strings.

    I am a string that has been
    split and added a border-bottom
    -------------------------------
    
    I am a string that has been
    ---------------------------
    split and underlined
    --------------------
    

    Apologies for using code formatting rather than properly rending these examples, but you can see the point I'm trying to make.

提交回复
热议问题