search

Home  >  Q&A  >  body text

How to do element selection inside another element?

<p>I have a question about CSS selectors. When a <code><div></code> with a specific class name is inside a <code><ul></code> with a class name <code>saft</code> How should I choose it? This CSS class is used elsewhere and I don't want to change the style everywhere. </p> <pre class="brush:php;toolbar:false;"><div id="floater"> <ul class="saft"> <li><div class="textSlide"></li> </ul> </div></pre>
P粉590929392P粉590929392468 days ago503

reply all(2)I'll reply

  • P粉463811100

    P粉4638111002023-08-23 10:14:27

    Just execute:

    ul.saft .textSlide {

    This will achieve the functionality you require

    reply
    0
  • P粉549412038

    P粉5494120382023-08-23 00:34:30

    Just use the CSS descendant selector (one space) between the parent element and the child element:

    ul.saft div.textSlide {
        /* CSS规则 */
    }

    * {
      margin: 0;
      padding: 0
    }
    
    li {
      list-style-type: none;
    }
    
    ul.saft div.textSlide {
      background-color: #f90;
      font-weight: #000;
    }
    <ul class="saft">
      <li>
        <div class="textSlide">在textSlide类元素中的一些文本</div>
      </li>
    </ul>
    <div class="textSlide">更多文本,也在textSlide元素中</div>

    reply
    0
  • Cancelreply