Sie sind auf Seite 1von 11

CSS Selectors

Task: 1

Select all elements with class="intro" and set background color as red.

OUTPUT:

Task: 2

Select the element with id="firstname" and set background color as yellow.

<html>
<head>
    <style>
        #firstname{
            background-color: yellow;
        }

        </style>
</head>
<body>
   <h1>Welcome to My Homepage</h1>
   <div class="intro">
       <p id="firstname">My name is Donald</p>
       <p id="hometown">I live in Duckburg.</p>
   </div>
   <p>My besy friend is Mickey.</p>
</body>
</html>

OUTPUT:

Task: 3

Select all elements in given HTML code and set background color as yellow.
OUTPUT:

Task: 4

Select all <p> elements and set background color as yellow and font color as red.
OUTPUT:

Task: 5

Select all <p> elements with class="intro" and set background color as green and font color as
white.
OUTPUT:

Task: 6

Select all <h1> elements and all <p> elements and set background color as green and font color
as pink.
OUTPUT:

Task: 7
Select and style every <p> element that is inside <div> elements and set background color as
green and font color as pink.

OUTPUT:

Task: 8

Select all <p> elements where the parent is a <div> element and set background color as green.
OUTPUT:

Task: 9

Select all <p> elements that are placed immediately after <div> elements and set background
color as red.
OUTPUT:

Task: 10

Style all <a> elements with a target attribute: and set background color as pink.
OUTPUT:

Task: 11

Select and style a link when you mouse over it and change color to red.
OUTPUT:

Das könnte Ihnen auch gefallen