text-decoration: underline vs border-bottom

后端 未结 7 2009
后悔当初
后悔当初 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:28

    setting your text to display inline (actually, it should be that by default) will cause the border-bottom to render much as a text-decoration rule.

    however, i presume that you want to use this technique on links by doing the following:

    /* my super eye catching dual colour link */
    a {
      color:black;
      border-bottom:1px solid red;
    }
    

    which is all well and good, but you'll find that wherever you have an img tag inside a link, the image will have a red border under it.

    if you can figure out a way to target the parent of a page element (the image) using existing selectors and no javascript, i'll buy you a beer but i don't think you'll have much luck.

    using "text-decoration" avoids this issue altogether as an image is clearly not text, it will not render an underline when inside a link.

    if you have complete control over your markup, i suppose you can bumble your way through by adding classes to every link, but if you're working with any popular CMS system, you're going to struggle with this idea.

提交回复
热议问题