diff options
Diffstat (limited to 'css/06-css-units/index.html')
| -rw-r--r-- | css/06-css-units/index.html | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/css/06-css-units/index.html b/css/06-css-units/index.html new file mode 100644 index 0000000..6b6b872 --- /dev/null +++ b/css/06-css-units/index.html @@ -0,0 +1,111 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Modern CSS Units Demo</title> + <style> + /* 1. Root Definition: Using px to establish a base size */ + :root { + font-size: 16px; /* Base size for root (1rem = 16px) */ + } + + /* Reset and Box Sizing */ + * { + box-sizing: border-box; + margin: 0; + padding: 0; + } + + body { + font-family: Arial, sans-serif; + color: #333; + } + + /* 2. Viewport Height & Width: vh, vw */ + .hero { + height: 80vh; /* Takes up 80% of the viewport height */ + width: 100vw; /* Takes up 100% of the viewport width */ + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + text-align: center; + color: white; + padding: 2rem; + } + + /* 3. Root em (rem): rem for scalable typography */ + .hero h1 { + font-size: 3rem; /* 3 x 16px = 48px */ + margin-bottom: 1rem; /* 1 x 16px = 16px */ + } + + .hero p { + font-size: 1.25rem; /* 1.25 x 16px = 20px */ + max-width: 60ch; /* Limits the width to about 60 characters for readability */ + } + + /* 4. Content Area */ + .content { + padding: 3rem 5%; /* Padding utilizes rem and percentage */ + max-width: 1200px; /* Absolute max-width constraint */ + margin: 0 auto; + } + + /* 5. Em unit: em for element-specific relative sizing */ + .card { + background-color: #f9f9f9; + border: 1px solid #ddd; + padding: 2em; /* Padding is relative to the card's own font-size */ + margin-bottom: 2rem; + border-radius: 0.5em; /* Border radius scales with the card's font */ + } + + .card h2 { + font-size: 2em; /* 2 x card base font-size */ + margin-bottom: 0.5em; + } + + .card p { + font-size: 1em; /* Matches the card base font-size */ + line-height: 1.6; + } + + /* 6. Percentage (%) and Pixels (px) */ + .image-container { + width: 100%; /* Takes 100% of the parent card's width */ + max-width: 400px; /* Max width constraint in pixels */ + margin: 1rem auto 0 auto; + } + + .image-container img { + max-width: 100%; + height: auto; + border-radius: 8px; /* Strict absolute unit for rounding */ + display: block; /* Removes unwanted baseline spacing */ + } + </style> +</head> +<body> + + <div class="hero"> + <h1>Responsive Layout with CSS Units</h1> + <p>This section uses <strong>vh</strong> for height and <strong>vw</strong> for width. The typography uses <strong>rem</strong> and <strong>ch</strong>.</p> + </div> + + <div class="content"> + <div class="card"> + <h2>The Card Heading</h2> + <p>This card's padding and margins scale relative to its own font-size using the <strong>em</strong> unit. The card width is controlled by percentages and absolute pixels.</p> + <div class="image-container"> + <!-- Using percentage and px for sizing --> + <a href="https://www.adhikarana.org/" target="_blank"><img src="images/hulftsdorp.jpg" alt="Hulftsdorp, Colombo"> + </div> + </div> + </div> + +</body> +</html> + |
