0

I have following HTML markup enter image description here

How do i select text inside this

  • As you can see inside that

  • there is a div i dont want to affect contents on that div.
  • octopus
    • 155
    • 3
    • 13
    • Also http://stackoverflow.com/questions/5080365/css-to-prevent-child-element-from-inheriting-parent-styles – CalvT Jun 22 '16 at 14:05

    3 Answers3

    2

    Text nodes can't be selected with CSS. You have to give some rules to the li, and then give rules to the div inside the li to override the styles that it gets from its parent, or wrap the text on some other element like a span.

    Jose Manuel
    • 165
    • 2
    • 8
    1

    You can't select only that text. So style the div too:

    ul,
    li div {
      color: black;
    }
    li {
      color: green;
    }
    <ul>
      <li>
        Text
        <div>Div Text</div>
      </li>
      <li>
        Text
        <div>Div Text</div>
      </li>
    </ul>
    CalvT
    • 3,123
    • 6
    • 37
    • 54
    1

    With the regular CSS methods you can't do that.

    I suggest to put a <span> around it and assig a class to it which you can style.

    Johannes
    • 64,305
    • 18
    • 73
    • 130