Bulma CSS Framework

repository·main·Indexed 13 days ago

https://github.com/jgthms/bulma

A modern, Flexbox-based CSS framework providing a complete styling layer without bundled JavaScript. Version 1.0.4 is environment agnostic and compatible with any frontend logic implementation. It features a responsive grid system with columns and tiles, a two-tier form system using .field and .control elements, and supports installation via NPM, Yarn, Bower, or CDN.

Tokens
10.6K
Snippets
34
Records
60
Agent score
95%

What's inside Bulma

  1. Explore Bulma related projects and ecosystem

    main

    Bulma has a wide ecosystem of related projects, including framework-specific component libraries (React, Vue, Angular, Svelte, Blazor, Elm, Ember), integration tools (Rails, Django, Laravel, WordPress), and specialized extensions (Social buttons, Modal effects, Attribute selectors).

    Key ecosystem categories include:

    • Framework Bindings: Bloomer (React), Buefy (Vue), @angular-bulma (Angular), Svelte Bulma Components (Svelte), BulmaRazor (Blazor).
    • Theming & Customization: Bulmaswatch (Themes), Bulma Customizer (Bespoke builds), bulma-fluent (Microsoft Fluent Design).
    • Integrations: bulma-rails (Rails), Django Bulma (Django), Laravel Enso (Laravel).
    • Utilities: bulma-helpers (Atomic CSS), Bulma-Social (Social buttons).
  2. Understand Bulma's CSS-only architecture

    main

    Bulma is a CSS-only framework. It provides a single output file (bulma.css) and contains no JavaScript.

    This makes Bulma 'environment agnostic': it serves strictly as the style layer, allowing you to use your own JavaScript implementation for interactivity. You can use the compiled CSS 'out of the box' or download the Sass source files if you wish to customize the variables.

  3. Understand Bulma Color Palettes and CSS Variables

    main

    Bulma automatically generates a collection of CSS variables for its 7 primary colors: text, link, primary, info, success, warning, and danger. These variables allow you to access various shades, lightness values, and inversion colors for each palette.

    For a color like primary, Bulma generates:

    • --bulma-primary: The base color.
    • --bulma-primary-rgb: The RGB components (useful for rgba(var(--bulma-primary-rgb), alpha)).
    • --bulma-primary-h, --bulma-primary-s, --bulma-primary-l: The Hue, Saturation, and Lightness components.
    • --bulma-primary-base: Alias for --bulma-primary.
    • --bulma-primary-invert: A color designed to look good as foreground on the primary color.
    • --bulma-primary-light / --bulma-primary-dark: The color at 90% and 20% lightness respectively.
    • --bulma-primary-soft / --bulma-primary-bold: Adaptive colors for light/dark mode.
    • --bulma-primary-on-scheme: A color that looks good on the page's default background color.
  4. How the `.field` and `.control` elements work together

    main

    Bulma uses a two-tier system for form elements to separate layout concerns from control styling:

    1. .field (The Block Container): Acts as the primary container for form groups. It handles layout modifiers such as .has-addons, .is-grouped, and .is-horizontal. It also contains structural elements like .field-label, .field-body, and .help.

    2. .control (The Inline Container): Acts as a wrapper for specific form inputs. It is used for styling elements that include icons, loading states, or specific input types. A .control should only contain a .button, .input, .select, .textarea, or an .icon.

    Key changes in the architecture:

    • .control can no longer contain .help elements or other .control elements.
    • Layout modifiers (like .is-grouped) must now be applied to the .field element, not the .control element.
    • .help text should be placed inside the .field container, outside of the .control wrapper.
    <!-- Correct Structure -->
    <div class="field">
      <label class="label">Label</label>
      <p class="control has-icon has-icon-right">
        <input class="input" type="text">
        <span class="icon is-small"><i class="fas fa-check"></i></span>
      </p>
      <p class="help">Help text goes here</p>
    </div>
  5. How the `.block` class provides automatic spacing

    main

    The .block class is a utility used to provide consistent vertical spacing between elements. When an element is given the .block class, it automatically applies a 1.5rem bottom margin, provided it is not the last child in its container.

    This behavior is integrated into many Bulma components, allowing them to be spaced evenly when placed sequentially within a container. To disable this automatic spacing on a component, you can use margin utility classes like mb-0 (margin-bottom: 0).

    <!-- Example of automatic spacing using Bulma components -->
    <div class="block">
      <div class="notification is-success">
        Message with automatic bottom margin.
      </div>
    
      <nav class="pagination" role="navigation">
        <!-- This pagination will be spaced 1.5rem below the notification -->
        <a class="pagination-previous">Previous</a>
        <a class="pagination-next">Next</a>
      </nav>
    </div>
  6. Understand the scope of Bulma CSS Variables

    main

    Bulma uses CSS Variables (custom properties) for styling. These variables are scoped in two ways:

    1. Global Scope: Defined at the :root level. These act as defaults for the entire application.
    2. Component Scope: Defined within specific classes (e.g., .button).

    Variables defined at a more specific component scope will override the global values. This allows you to customize a specific component without affecting the rest of the application.

    :root {
      /* Default global value */
      --bulma-size-medium: 1.25rem;
    }
    
    .button {
      /* Overrides the global value for buttons only */
      --bulma-size-medium: 1.5rem;
    }
  7. What are themes in Bulma

    main

    In Bulma, a theme is a collection of CSS variables. Bulma provides two built-in themes:

    • light.scss (required): The default theme that sets base values for all CSS variables.
    • dark.scss (optional): An alternative theme for dark mode.

    Bulma handles theme switching using three different mechanisms via the /sass/themes/_index.scss file:

    1. Media Queries: Using @media (prefers-color-scheme: $name) to respect system settings.
    2. HTML Attributes: Using the [data-theme=$name] attribute.
    3. CSS Classes: Using the .theme-$name selector.
  8. How Bulma manages Sass variables for customization

    main

    Bulma is designed for high customizability through an extensive system of Sass variables. There are approximately 415 Sass variables distributed across 28 files.

    To ensure developers can effectively customize the framework, Bulma uses an automated process to keep its documentation in sync with the source code. A script parses the Sass source files and generates JSON data representing the variables. This allows the documentation to automatically display the variable name, its type, and its computed value (where applicable), ensuring that the documentation always reflects the current state of the source code.