setting font color of inside a li tag

后端 未结 9 1468
臣服心动
臣服心动 2021-02-20 07:26

My markup looks like:


I want th

相关标签:
9条回答
  • 2021-02-20 07:27
    .c2 a
    {
         color: red;
    }
    
    0 讨论(0)
  • 2021-02-20 07:29

    The most specific CSS selectors would probably be

    div.c1 > li.c2 > a:link,
    div.c1 > li.c2 > a:active,
    div.c1 > li.c2 > a:hover,
    div.c1 > li.c2 > a:visited {
        color: red;
    }
    

    The more specific the CSS selectors, the less work for the browser's rendering engine.

    However, something is wrong with your markup if this is supposed to be HTML and the <li> element's parent is a <div> instead of <ol> or <ul>.

    0 讨论(0)
  • 2021-02-20 07:33
    .c1 .c2 a {
      color: red;
    }
    
    0 讨论(0)
  • 2021-02-20 07:38
    <div class="c1">
          <li class="c2"><a href="">blah</a></li>
    </div>
    <style>
      div.c1 li.c2 a { color: red; }
    </style>
    
    0 讨论(0)
  • 2021-02-20 07:39

    Use this style definition in your css-file:

    div.c1 li.c2 a {
      color: red;
    }
    

    PS: Having your <li> tag inside your <div>-tag without an <ul>-tag is not recommended.

    0 讨论(0)
  • 2021-02-20 07:42

    Use the following rule:

    div.c1 li.c2 a {
        color: red;
    }
    

    This matches a tags inside of li tags with class c2 inside of div tags with class c1.

    For added uniqueness, you might want to give the a tag its own class name.

    Also, li tags should only appear inside of list tags. (ul or ol).
    Did you mean <li class="c1">?

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