Skip to content

Commit 27eb2b2

Browse files
committed
FAB mobile icon not centered fix
1 parent 2e15da4 commit 27eb2b2

File tree

1 file changed

+68
-92
lines changed

1 file changed

+68
-92
lines changed

css/components/fab.css

Lines changed: 68 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,77 @@
11
/* Base Floating Action Button (FAB) Styling */
22
.fab {
3-
position: fixed;
4-
bottom: var(--space-8, 2rem);
5-
right: var(--space-8, 2rem);
6-
display: inline-flex;
7-
align-items: center;
8-
justify-content: center;
9-
padding: clamp(1rem, 2vw, 1.5rem);
10-
font-size: 1.5rem;
11-
background-color: var(--variant-bg, var(--primary));
12-
color: var(--variant-text, #ffffff);
13-
cursor: pointer;
14-
border: none;
15-
box-shadow: var(--shadow-lg, 0 4px 8px rgba(0, 0, 0, 0.2));
16-
border-radius: var(--radius-full, 50%);
17-
transition:
18-
background-color var(--transition-colors, 0.2s ease),
19-
transform var(--transition-transform, 0.2s ease),
20-
box-shadow var(--transition-transform, 0.2s ease);
21-
z-index: var(--z-50);
22-
}
23-
24-
/* FAB Hover and Active States */
25-
.fab:hover {
26-
transform: translateY(-3px);
27-
box-shadow: var(--shadow-md, 0 6px 10px rgba(0, 0, 0, 0.15));
28-
background-color: var(--variant-hover-bg, var(--primary-hover));
29-
}
30-
31-
.fab:active {
32-
transform: translateY(1px);
33-
box-shadow: var(--shadow-sm, 0 2px 4px rgba(0, 0, 0, 0.1));
34-
}
35-
36-
/* Shape Variants */
37-
.fab[data-shape="circular"] {
38-
border-radius: var(--radius-full, 50%);
39-
}
40-
41-
.fab[data-shape="square"] {
42-
border-radius: 0;
43-
}
44-
45-
.fab[data-shape="rectangular"] {
46-
border-radius: var(--radius-md, 0.375rem);
47-
padding: clamp(0.75rem, 1.5vw, 1rem) clamp(1.5rem, 3vw, 2rem);
48-
}
49-
50-
/* Style Variants */
51-
.fab[data-style="bordered"] {
52-
border: 2px solid var(--variant-border, var(--primary-dark));
53-
}
54-
55-
.fab[data-style="outlined"] {
56-
background-color: transparent;
57-
border: 2px solid var(--variant-bg, var(--primary));
58-
color: var(--variant-bg, var(--primary));
59-
box-shadow: none;
60-
}
61-
62-
.fab[data-style="outlined"]:hover {
63-
background-color: var(--variant-hover-bg, var(--primary-hover));
64-
color: var(--variant-text, #ffffff);
65-
}
66-
67-
.fab[data-style="ghost"] {
68-
background-color: transparent;
69-
color: var(--variant-bg, var(--primary));
70-
box-shadow: none;
71-
}
72-
73-
.fab[data-style="ghost"]:hover {
74-
background-color: var(--neutral-100, #f1f5f9);
75-
}
76-
77-
/* Icon Alignment Fix for All Screens */
78-
.fab > * {
79-
display: flex;
80-
align-items: center;
81-
justify-content: center;
82-
font-size: inherit;
83-
height: 100%;
84-
width: 100%;
85-
}
86-
87-
/* Responsive Adjustments */
88-
@media (max-width: 768px) {
89-
.fab {
3+
position: fixed;
4+
bottom: var(--space-8, 2rem);
5+
right: var(--space-8, 2rem);
6+
display: flex; /* Flexbox ensures centering of children */
7+
align-items: center; /* Vertically center content */
8+
justify-content: center; /* Horizontally center content */
9+
padding: 0; /* Remove default padding for precise centering */
10+
font-size: 1.5rem;
11+
width: clamp(3rem, 8vw, 4rem); /* Ensure FAB is always square */
12+
height: clamp(3rem, 8vw, 4rem); /* Match width for perfect circle */
13+
background-color: var(--variant-bg, var(--primary));
14+
color: var(--variant-text, #ffffff);
15+
cursor: pointer;
16+
border: none;
17+
box-shadow: var(--shadow-lg, 0 4px 8px rgba(0, 0, 0, 0.2));
18+
border-radius: var(--radius-full, 50%); /* Circular shape */
19+
transition:
20+
background-color var(--transition-colors, 0.2s ease),
21+
transform var(--transition-transform, 0.2s ease),
22+
box-shadow var(--transition-transform, 0.2s ease);
23+
z-index: var(--z-50);
24+
}
25+
26+
/* Ensure Icon Stays Centered Inside FAB */
27+
.fab > * {
28+
display: flex;
29+
align-items: center;
30+
justify-content: center;
31+
width: 100%; /* Icon scales with FAB size */
32+
height: 100%; /* Icon scales with FAB size */
33+
font-size: inherit; /* Inherit FAB font size */
34+
line-height: 1; /* Prevent text alignment issues */
35+
}
36+
37+
/* FAB Hover and Active States */
38+
.fab:hover {
39+
transform: translateY(-3px);
40+
box-shadow: var(--shadow-md, 0 6px 10px rgba(0, 0, 0, 0.15));
41+
background-color: var(--variant-hover-bg, var(--primary-hover));
42+
}
43+
44+
.fab:active {
45+
transform: translateY(1px);
46+
box-shadow: var(--shadow-sm, 0 2px 4px rgba(0, 0, 0, 0.1));
47+
}
48+
49+
/* Shape Variants */
50+
.fab[data-shape="circular"] {
51+
border-radius: var(--radius-full, 50%);
52+
padding: 0; /* Ensure circular shape is preserved */
53+
}
54+
55+
.fab[data-shape="square"] {
56+
border-radius: 0;
57+
}
58+
59+
.fab[data-shape="rectangular"] {
60+
border-radius: var(--radius-md, 0.375rem);
61+
padding: clamp(0.75rem, 1.5vw, 1rem) clamp(1.5rem, 3vw, 2rem);
62+
}
63+
64+
/* Responsive Adjustments */
65+
@media (max-width: 768px) {
66+
.fab {
9067
width: clamp(2.5rem, 8vw, 3rem);
9168
height: clamp(2.5rem, 8vw, 3rem);
9269
bottom: var(--space-4, 1rem);
9370
right: var(--space-4, 1rem);
9471
font-size: 1.25rem;
95-
}
96-
97-
.fab > * {
72+
}
73+
74+
.fab > * {
9875
font-size: 1.25rem;
99-
}
10076
}
101-
77+
}

0 commit comments

Comments
 (0)