How do I get this CSS text-decoration override to work?

前端 未结 6 2287
生来不讨喜
生来不讨喜 2020-11-22 11:49

Some days I swear I\'m going mad. This is one of those days. I thought my CSS was fairly straight-forward here, but it just doesn\'t seem to be working. What am I missing?

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 12:23

    The reason you´re seeing what you're seeing is that your rule

    ul > li.u
    

    takes preference over:

    ul > li > ul > li
    

    as a class is specified and that has more weight than the element selectors together.

    Edit: What you could try is:

    .u ul {
            text-decoration: none;
    }
    .u {
            text-decoration: underline;
    }
    

    and play around with that (perhaps you will have to use li.u instead of just .u).

    However, depending on the content you might want to wrap the underlined parts in q, em or strong tags and style these tags instead of using a class. That way you would be describing your content as well as styling it.

提交回复
热议问题