CSS content property not displaying

前端 未结 3 716
囚心锁ツ
囚心锁ツ 2021-02-13 04:11

I am new to CSS and I\'m following a book example:

Iv\'e copied the following from the book and saved it as HTML. all the css properties seem to work except the \"conten

相关标签:
3条回答
  • 2021-02-13 04:59

    content is used with :before or :after like so:

    div:after
    {
        content: "Hello, world!";
    }
    

    Regardless, I've only used content for special cases (to clear floated elements, for example). I've never actually used this to insert content. You generally want to separate content and presentation anyway, so I think this is a bad idea. Which book are you reading? :)

    0 讨论(0)
  • 2021-02-13 05:03

    The content property only applies to CSS pseudo-elements such as :before and :after.

    You cannot use it to set the content of an arbitrary element.

    0 讨论(0)
  • 2021-02-13 05:12

    The content property only works for :before and :after to prepend or append content to said nodes, like so:

    .email-address:before {
      content : "Email address: ";
    }
    <ul>
      <li class="email-address">myemail@gmail.com</li>
    </ul>

    The output would be

    • Email address: myemail@gmail.com

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