-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponsive.html
More file actions
169 lines (141 loc) · 4.11 KB
/
Copy pathResponsive.html
File metadata and controls
169 lines (141 loc) · 4.11 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
/* The full article is available on: https://mobalti.com/responsive-components-style-queries/ */
/* Register the custom property as non-inherited by setting the `inherits` descriptor to `false` to prevent it from inheriting down the DOM tree */
@property --size-items {
syntax: "small | medium | large";
inherits: false;
initial-value: small;
}
/* Update the custom property based on viewport size */
.content {
@media (width >=840px) {
--size-items: large;
}
}
/* Wrap the component definition in a layer to ensure consumer styles always win */
@layer design-system-components {
.button {
/* Base/default properties (represent the small size variant) */
block-size: 3rem;
border-radius: 1rem;
font: 500 1rem/1.5rem system-ui;
gap: 0.5rem;
padding: 0.75rem 1.75rem;
/* Responsive variations using container style queries */
&:not(.small) {
@container style(--size-items: medium) {
block-size: 5rem;
border-radius: 1.75rem;
font: 400 1.5rem/2rem system-ui;
gap: 0.75rem;
padding: 1.5rem 3rem;
}
@container style(--size-items: large) {
block-size: 6.5rem;
border-radius: 1.75rem;
font: 400 2rem/2.5rem system-ui;
gap: 1rem;
padding: 2rem 4rem;
}
}
/* Modifier classes for static size instances */
&.medium {
block-size: 5rem;
border-radius: 1.75rem;
font: 400 1.5rem/2rem system-ui;
gap: 0.75rem;
padding: 1.5rem 3rem;
}
&.large {
block-size: 6.5rem;
border-radius: 1.75rem;
font: 400 2rem/2.5rem system-ui;
gap: 1rem;
padding: 2rem 4rem;
}
}
}
/* Support styles for the demo */
@layer support {
html {
color-scheme: light dark;
}
body {
display: grid;
place-items: center;
background: light-dark(oklch(99% 0 0), oklch(17% 0 0));
}
.content {
display: flex;
gap: 0.25rem;
flex-wrap: wrap;
align-items: center;
padding: 1rem;
}
.button {
--_state: none;
--_background: light-dark(oklch(91% 0.05 237), oklch(39% 0.1 245));
background: var(--_background);
color: contrast-color(var(--_background));
border: none;
display: inline-flex;
align-items: center;
cursor: pointer;
position: relative;
overflow: clip;
user-select: none;
min-inline-size: fit-content;
white-space: nowrap;
&:hover {
--_state: oklch(from currentColor l c h / 0.8%);
}
&:focus-visible {
--_state: oklch(from currentColor l c h / 0.8%);
}
&:active {
--_state: oklch(from currentColor l c h / 0.1%);
}
&::before {
content: "";
position: absolute;
inset: 0;
background: var(--_state);
}
}
}
/* Reset */
@layer reset {
*,
::before,
::after {
box-sizing: border-box;
}
:where(:not(dialog)) {
margin: 0;
}
:where(html) {
-webkit-text-size-adjust: none;
@media (prefers-reduced-motion: no-preference) {
scroll-behavior: smooth;
}
}
:where(body) {
min-block-size: 100svb;
-webkit-font-smoothing: antialiased;
}
}
</style>
</head>
<body>
<section class="section">
<div class="content">
<button class="button">Responsive</button>
<button class="button small">Fixed small</button>
</div>
</section>
</body>
</html>