blob: 6b6b8726ced760e3415292f53283678d5e99fbe1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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>
|