Skip to content

Core Layout and Styling

The global layout and styling architecture relies on an Astro template (Layout.astro) to enforce semantic HTML structure, SEO metadata, and client-side interactivity for navigation and theming. Visual consistency is achieved through global.css, which utilizes Tailwind CSS to define a responsive grid system, a primary color palette, and CSS variables that adapt to user preferences via a dark-mode class applied to the <body>.

The site uses a single global layout template that wraps all pages. This template imports global styles and defines the standard <head> section, which includes Open Graph and Twitter meta tags, canonical URLs, and JSON-LD structured data 1.

The body structure consists of a fixed sidebar for navigation and a main content area. The sidebar contains the site logo, a list of main navigation links, a documentation section, and a theme toggle button. The main content area wraps the page-specific content in a content-wrapper div 2.

diagram

The sidebar provides navigation for “Main” and “Documentation” sections. Links are dynamically marked as active based on the current URL path using Astro’s Astro.url.pathname 1.

On mobile devices, the sidebar is hidden by default and can be toggled open using a hamburger menu button (.mobile-nav-toggle). The sidebar’s visibility is controlled by toggling the .is-open class on the .sidebar element 2.

The site supports light and dark modes. To prevent a flash of unstyled content (FOUC), a synchronous inline script applies the dark-mode class to the <body> before the first paint, checking localStorage or the system preference 1.

Users can toggle the theme using the .theme-toggle button. This action toggles the dark-mode class on the body and persists the user’s choice in localStorage 2. CSS transitions for background and text colors are enabled via JavaScript after the first paint to ensure smooth animations.

Global styles are defined in src/styles/global.css, which imports Tailwind CSS 3. The theme system is driven by a custom @custom-variant for dark mode, which targets elements within .dark-mode.

A custom primary color palette is defined using CSS variables (e.g., --color-primary-500: #3b82f6). These variables are used throughout the component classes to ensure consistent coloring across light and dark themes.

The body element has a light gradient background by default. In dark mode, the background switches to a dark gradient, and the text color changes to #ecf0f1. A pseudo-element (body::before) adds a subtle radial gradient overlay that adjusts its opacity in dark mode.

The .main-container uses Flexbox to position the fixed .sidebar and the flexible .main-content 4. On screens smaller than 768px, the sidebar is hidden off-screen (-translate-x-full) and slides in when .is-open is applied.

Key components like .card, .glass-card, and .btn are styled with Tailwind utility classes that include dark mode variants (e.g., dark:bg-gray-800). These components feature hover effects, shadows, and transitions that adapt to the current theme.