|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>Class Selector Examples</title> |
| 5 | + <style> |
| 6 | + /* Add some basic styling for clarity */ |
| 7 | + body { |
| 8 | + font-family: Arial, sans-serif; |
| 9 | + padding: 20px; |
| 10 | + background-color: #f9f9f9; |
| 11 | + color: #333; |
| 12 | + } |
| 13 | + |
| 14 | + h1 { |
| 15 | + font-size: 28px; |
| 16 | + margin-bottom: 20px; |
| 17 | + } |
| 18 | + |
| 19 | + p { |
| 20 | + font-size: 18px; |
| 21 | + margin-bottom: 10px; |
| 22 | + } |
| 23 | + |
| 24 | + .example { |
| 25 | + margin-bottom: 40px; |
| 26 | + border: 1px solid #ccc; |
| 27 | + padding: 20px; |
| 28 | + background-color: #fff; |
| 29 | + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); |
| 30 | + } |
| 31 | + |
| 32 | + .example-title { |
| 33 | + font-weight: bold; |
| 34 | + font-size: 24px; |
| 35 | + margin-bottom: 10px; |
| 36 | + } |
| 37 | + |
| 38 | + .example-description { |
| 39 | + margin-top: 5px; |
| 40 | + } |
| 41 | + |
| 42 | + code { |
| 43 | + display: inline-block; |
| 44 | + background-color: #000000; |
| 45 | + padding: 2px 4px; |
| 46 | + font-family: Consolas, monospace; |
| 47 | + font-size: 16px; |
| 48 | + color: aliceblue; |
| 49 | + } |
| 50 | + </style> |
| 51 | +</head> |
| 52 | +<body> |
| 53 | + <h1>Class Selector Examples</h1> |
| 54 | + |
| 55 | + <div class="example"> |
| 56 | + <h2 class="example-title">Example 1: Selecting elements with a specific class</h2> |
| 57 | + <p class="example-description">This example selects and applies styles to all elements with the class <code>.highlight</code>.</p> |
| 58 | + <p class="highlight">This paragraph has the class "highlight".</p> |
| 59 | + <p>This paragraph does not have the class "highlight".</p> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div class="example"> |
| 63 | + <h2 class="example-title">Example 2: Selecting elements with multiple classes</h2> |
| 64 | + <p class="example-description">This example selects and applies styles to all elements with both classes <code>.highlight</code> and <code>.text-center</code>.</p> |
| 65 | + <p class="highlight text-center">This paragraph has both the classes "highlight" and "text-center".</p> |
| 66 | + <p class="highlight">This paragraph only has the class "highlight".</p> |
| 67 | + </div> |
| 68 | + |
| 69 | + <div class="example"> |
| 70 | + <h2 class="example-title">Example 3: Selecting elements with a specific class within a parent element</h2> |
| 71 | + <p class="example-description">This example selects and applies styles to elements with the class <code>.highlight</code> that are inside a parent element with the class <code>.container</code>.</p> |
| 72 | + <div class="container"> |
| 73 | + <p class="highlight">This paragraph is inside a parent element with the class "container" and has the class "highlight".</p> |
| 74 | + <p class="highlight">This paragraph is also inside a parent element with the class "container" and has the class "highlight".</p> |
| 75 | + </div> |
| 76 | + <p class="highlight">This paragraph is not inside a parent element with the class "container".</p> |
| 77 | + </div> |
| 78 | + |
| 79 | +</body> |
| 80 | +</html> |
0 commit comments