x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- Default -->
<div class="avatar">
<img alt="CN" src="/assets/cartoon-93de1535.jpg" width="48" height="48" />
</div>
<!-- Button -->
<button class="btn avatar">
<img alt="CN" src="/assets/cartoon-93de1535.jpg" width="48" height="48" />
</button>
<!-- Fallback -->
<div class="avatar">
<span role="img">CN</span>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%# Default %>
<div class="avatar">
<%= image_tag "cartoon.jpg", size: 48, alt: "CN" %>
</div>
<%# Button %>
<button class="btn avatar">
<%= image_tag "cartoon.jpg", size: 48, alt: "CN" %>
</button>
<%# Fallback %>
<div class="avatar">
<%= tag.span "CN", role: "img" %>
</div>
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
.avatar {
--radius: var(--rounded-full);
--size: var(--avatar-size, var(--size-10));
block-size: var(--size);
border-radius: var(--radius);
display: flex;
flex-shrink: 0;
inline-size: var(--size);
overflow: hidden;
&:is(.btn) {
--btn-padding: 0;
--btn-icon-color: none;
--btn-radius: var(--radius);
}
&:is(.btn):hover {
filter: var(--brightness-90);
}
img {
aspect-ratio: var(--aspect-square);
block-size: var(--size-full);
inline-size: var(--size-full);
object-fit: cover;
}
span[role=img] {
align-items: center;
background-color: var(--color-border-light);
block-size: var(--size-full);
border-radius: var(--radius);
display: flex;
font-size: calc(var(--size) * .4);
inline-size: var(--size-full);
justify-content: center;
user-select: none;
}
}
Java Script is not required or multiple files are needed, check the notes.