Bulma Components
Bulma provides a rich set of components that simplify the creation of common elements in web interfaces. In this guide, we'll explore two essential Bulma components: Modals and Tabs, along with Forms and Buttons. We'll provide examples to help you integrate these components into your projects.
1. Modals and Tabs:
- Modals:
Modals in Bulma are used to create overlay windows that appear on top of the main content. They are useful for displaying additional information, forms, or interactive elements without navigating away from the current page.
<div class="modal" id="myModal">
<div class="modal-background"></div>
<div class="modal-content">
<!-- Modal content goes here -->
<p class="box">This is a modal. You can add any content you want.</p>
</div>
<button class="modal-close is-large" aria-label="close" onclick="toggleModal('myModal')"></button>
</div>The modal is activated by JavaScript using the is-active class. Here's an example of a function to toggle the modal's visibility:
function toggleModal(modalId) {
const modal = document.getElementById(modalId);
modal.classList.toggle('is-active');
}You can trigger this function when a button or link is clicked.
- Tabs:
Tabs in Bulma are used to organize content into a tabbed interface. Each tab corresponds to a section of content, making it easy to switch between different views.
<div class="tabs">
<ul>
<li class="is-active"><a>Pictures</a></li>
<li><a>Music</a></li>
<li><a>Videos</a></li>
</ul>
</div>
<div class="tab-content">
<!-- Content for the active tab goes here -->
</div>The is-active class indicates the currently active tab. You can add this class dynamically based on user interactions.
2. Forms and Buttons:
- Forms:
Bulma styles HTML forms to provide a clean and consistent appearance. Form elements like input fields, checkboxes, and radio buttons are styled out of the box.
<form>
<div class="field">
<label class="label">Username</label>
<div class="control">
<input class="input" type="text" placeholder="Enter your username">
</div>
</div>
<div class="field">
<label class="label">Password</label>
<div class="control">
<input class="input" type="password" placeholder="Enter your password">
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-primary">Submit</button>
</div>
</div>
</form>- Buttons:
Bulma provides versatile button styles, including different sizes and colors. You can customize the appearance by applying classes such as is-primary, is-info, or is-danger.
<button class="button is-primary">Primary Button</button>
<button class="button is-info">Info Button</button>
<button class="button is-danger">Danger Button</button>You can also use styles for outlined buttons and inverted colors by adding is-outlined or is-inverted classes.
Bulma's components, including modals, tabs, forms, and buttons, contribute to the framework's simplicity and flexibility. By leveraging these components, developers can create visually appealing and functional web interfaces with ease. Customization options and straightforward integration make Bulma a powerful choice for building modern web applications.