search

Home  >  Q&A  >  body text

Descendant selectors vs. element selectors

Directly using the element selector to define em has the same function as the descendant selector

雨落破晓雨落破晓1912 days ago1623

reply all(1)I'll reply

  • MrThinco

    MrThinco2019-11-22 09:52:24

    Yes. However, sometimes, we will choose to use the descendant selector instead of the element selector. For example, let me write a piece of code for you. In the following code, I want to modify the font color of the first em:

    <div><em>我是程序界的彭于晏</em></div>
    <span><em>我是程序界的周杰伦</em></span>

    If the element selector is used directly here, the color of the two sentences in em will be changed, but I only want to change the words in the first em, then at this time, the descendant selector will show its effect.

    reply
    0
  • Cancelreply