To prevent the badges from overflowing in the right card when the screen size decreases, you'll need to make the badge containers more responsive. This involves allowing the badges to wrap to the next line and adjusting their sizes appropriately using CSS. Here's a step-by-step guide to achieve this:
1. Allow Badges to Wrap
Modify the .badge-container to enable wrapping of badges when there's insufficient horizontal space. This ensures that badges move to the next line instead of overflowing.
Update .badge-container Style:
.badge-container {
display: flex;
flex-wrap: wrap; /* Allow badges to wrap */
gap: 0.5em;
}
2. Adjust Badge Sizes on Smaller Screens
To ensure badges scale properly on smaller screens, adjust their font-size and padding. This makes sure that badges remain readable without taking up excessive space.
Add Media Queries for Smaller Screens:
@media (max-width: 768px) {
.badge {
padding: 0.2em 0.5em; /* Reduce padding */
font-size: 0.75em; /* Decrease font size */
}
/* Optional: Adjust badge-container further if needed */
.badge-container {
gap: 0.3em; /* Reduce gap between badges */
}
}
3. Ensure Team Cards are Flexible
Ensure that the team cards themselves are flexible and can accommodate wrapping content without fixed widths that could cause overflow.
Adjust .team Style:
.team {
display: flex;
flex-direction: column; /* Stack content vertically */
/* Remove any fixed widths if present */
}
4. Optional: Responsive Layout for Team Headers
If the team headers (which include the badges) are still causing overflow, you might want to adjust their layout to stack vertically on smaller screens.
Update Team Summary Layout:
Since you're using Flexbox in the summaries, ensure they also wrap properly.
.team details summary {
display: flex;
flex-direction: column; /* Stack team name and badges vertically */
align-items: flex-start; /* Align items to the start */
}
@media (min-width: 769px) {
.team details summary {
flex-direction: row; /* Restore horizontal layout on larger screens */
align-items: center;
}
}
5. Final Adjustments
Ensure that all badge styles inherit from their parent containers appropriately and that there's no conflicting CSS that might prevent wrapping or scaling.
Ensure Inherited Styles for Badges:
.badge-container {
display: flex;
flex-wrap: wrap;
gap: 0.5em;
}
.badge {
display: inline-block;
padding: 0.25em 0.75em;
border-radius: 12px;
font-size: 0.85em;
color: #ffffff;
white-space: nowrap; /* Prevent badges from breaking internally */
}
@media (max-width: 768px) {
.badge {
padding: 0.2em 0.5em;
font-size: 0.75em;
}
.badge-container {
gap: 0.3em;
}
.team details summary {
flex-direction: column;
align-items: flex-start;
}
}
6. Full Updated CSS
Here's the complete updated CSS incorporating all the changes:
.dashboard-container {
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
}
.top-section {
padding: 1rem 2rem;
text-align: left;
background-color: #f0f4f8;
border-bottom: 1px solid #dfe3e8;
}
.top-section h1 {
margin: 0;
font-size: 1.75rem;
color: #2e3a59;
}
.top-section p {
margin: 0.5rem 0 0;
color: #53657d;
}
.main-section {
display: flex;
height: 100%;
overflow: hidden;
}
.calendar-container {
width: 70%;
padding: 1rem;
flex: 1;
min-width: 300px;
overflow-y: auto;
}
.right-container {
width: 30%;
padding: 1rem;
background-color: #ffffff;
border-left: 1px solid #dfe3e8;
overflow-y: auto;
flex: none;
min-width: 300px;
height: 100%;
position: relative;
}
.right-container.show {
display: block;
}
.details-container {
display: flex;
flex-direction: column;
}
.details-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.details-header h2 {
margin: 0;
font-size: 1.5rem;
color: #2e3a59;
}
/* Hide the close button on larger screens */
.close-button {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: #888;
display: none; /* Hidden by default */
}
/* Display the close button only on small screens */
@media (max-width: 768px) {
.close-button {
display: block;
}
}
.time-slot {
margin-bottom: 1em;
}
.time-label {
font-weight: bold;
margin-right: 0.5em;
}
.badge-container {
display: flex;
flex-wrap: wrap; /* Allow badges to wrap */
gap: 0.5em;
}
.badge {
display: inline-block;
padding: 0.25em 0.75em;
border-radius: 12px;
font-size: 0.85em;
color: #ffffff; /* Default text color */
white-space: nowrap; /* Prevent badges from breaking internally */
}
.badge-office {
background-color: #6BCB77; /* Green */
}
.badge-wfh {
background-color: #FFD93D; /* Yellow */
color: #000000; /* Black text for better visibility */
}
.badge-office-calendar {
background-color: #6BCB77; /* Green */
color: #ffffff;
font-size: 0.7em;
padding: 2px 4px;
border-radius: 8px;
}
.badge-wfh-calendar {
background-color: #FFD93D; /* Yellow */
color: #000000; /* Black text for better visibility */
font-size: 0.7em;
padding: 2px 4px;
border-radius: 8px;
}
.teams {
margin-left: 0.5em;
}
.team {
display: flex; /* Added for flexibility */
flex-direction: column; /* Stack content vertically */
margin-bottom: 0.5em;
border: 1px solid #dfe3e8;
border-radius: 8px;
padding: 0.5em;
background-color: #f9fafb;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.team details summary {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: bold;
cursor: pointer;
color: #2e3a59;
flex-wrap: wrap; /* Allow content to wrap */
}
.team details[open] summary {
border-bottom: 1px solid #dfe3e8;
margin-bottom: 0.5em;
}
.team .badge {
margin-left: 0.5em;
}
.staff-list {
display: flex;
flex-direction: column;
margin-top: 0.5em;
}
.staff-card {
display: flex;
align-items: center;
border: 1px solid #dfe3e8;
border-radius: 6px;
padding: 0.5em;
margin-bottom: 0.5em;
background-color: #ffffff;
}
.staff-card .status-indicator {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 0.5em;
}
.staff-card .status-indicator.green {
background-color: #6BCB77;
}
.staff-card .status-indicator.yellow {
background-color: #FFD93D;
}
.staff-card .staff-name {
font-weight: 500;
color: #2e3a59;
}
.right-container details {
margin: 0.5em 0;
}
.right-container summary {
font-weight: bold;
cursor: pointer;
color: #2e3a59;
}
.fc {
width: 100%;
height: 100%;
}
.no-selection {
text-align: center;
color: #888;
margin-top: 2rem;
}
.fc-event-main {
padding: 2px;
}
.fc-daygrid-event {
white-space: normal !important;
}
.calendar-event {
/* Additional styling if needed */
}
.fc-daygrid-event-harness {
margin-bottom: 2px !important;
}
/* Adjust the calendar height */
.fc .fc-view-harness {
min-height: 0;
}
/* Hide the scrollbar but allow scrolling */
.calendar-container::-webkit-scrollbar {
width: 0;
height: 0;
}
.right-container::-webkit-scrollbar {
width: 8px;
}
.right-container::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
border-radius: 4px;
}
.right-container::-webkit-scrollbar-track {
background-color: transparent;
}
/* Media query for responsive layout */
@media (max-width: 768px) {
.calendar-container {
width: 100%;
}
.right-container {
position: fixed; /* Change to fixed for overlay */
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(255, 255, 255, 0.95); /* Semi-transparent background */
transform: translateX(100%);
transition: transform 0.3s ease-in-out;
z-index: 1000;
overflow-y: auto;
padding: 1rem;
}
.right-container.show {
transform: translateX(0);
}
/* Ensure text within badges remains black on yellow backgrounds */
.badge-wfh, .badge-wfh-calendar {
color: #000000 !important;
}
.team details summary {
flex-direction: column; /* Stack team name and badges vertically */
align-items: flex-start; /* Align items to the start */
}
}
@media (max-width: 768px) {
.main-section {
flex-direction: column;
}
.right-container {
width: 100%;
min-width: unset;
height: auto;
position: fixed; /* Ensure it overlays */
right: 0;
top: 0;
box-shadow: none;
background-color: #ffffff;
}
.calendar-container {
width: 100%;
height: 100%;
}
.details-header {
display: flex;
justify-content: space-between;
align-items: center;
}
}
/* New Styles for Conditional Text Colors */
.yellow-event {
color: #000000 !important;
}
.default-event {
color: #ffffff !important;
}
.yellow-event .badge,
.default-event .badge {
color: inherit !important;
}
7. Verify and Test
After implementing these changes:
- Test on Various Screen Sizes: Ensure that the badges wrap correctly and do not overflow on different screen widths, especially below 768px.
- Check Readability: Make sure that the badges remain readable with the adjusted font sizes and padding.
- Ensure Consistency: Verify that the overall layout remains consistent and that no other elements are negatively affected by these changes.
8. Additional Recommendations
-
Use Flex Properties for Badges: If you want badges to take available space more intelligently, consider using flex: 1 or similar flex properties.
.badge {
flex: 1 1 auto; /* Allows badges to grow and shrink */
}
-
Limit Badge Content: Ensure that the text inside badges is concise. Long text can still cause overflow issues. Consider abbreviating text where possible.
For example, instead of "In Office ({{ slot.inOffice }}/{{ slot.total }})", you might use "Office: {{ slot.inOffice }}/{{ slot.total }}" or even shorter if needed.
-
Use Tooltips: If reducing text compromises clarity, implement tooltips that show full information when a user hovers over or taps on a badge.
By following these steps and adjusting your CSS accordingly, the badges should scale properly and no longer overflow out of their containers on smaller screens.