Select every element preceded by a CSS element

WBOY
Release: 2023-09-12 19:17:02
forward
1472 people have browsed it

选择前面有 CSS 元素的每个元素

Use the element ~ element selector to select the

    element, preceded by the

    element. You can try running the following code to implement this example

    Example

    Live Demo

    <!DOCTYPE html>
    <html>
       <head>
          <style>
             p~ul {
                color: white;
                background-color: blue;
             }
          </style>
       </head>
       <body>
          <h1>Demo Website</h1>
          <h2>Fruits</h2>
          <div>
             <p>Vegetables are good for health.</p>
             <ul>
                <li>Spinach</li>
                <li>Onion</li>
                <li>Capsicum</li>
             </ul>
          </div>
          <p>Fruits are good for health.</p>
          <ul>
             <li>Apple</li>
             <li>Orange</li>
             <li>Kiwi</li>
          </ul>
       </body>
    </html>
    Copy after login

    The above is the detailed content of Select every element preceded by a CSS element. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template