Bulma - The Inline Imperative of Button Class

I recently started using Bulma and have been experimenting with creating a basic webpage using it.

I've encountered an annoying issue where the "button is-large" class seems to be making elements on my page display inline.

Below is a simple demonstration of the problem:

  <div class="column" style="height: 200px">
    <a class="button is-fullwidth" style="height: 100%">
       <p> <img src="https://d30y9cdsu7xlg0.cloudfront.net/png/30611-200.png" alt=""> </p>
       <p class="title">Print Release</p>
    </a>
  </div>

The elements in the code above are appearing inline instead of stacked vertically.

I would like the contents inside the "a tag" to stack on top of each other. However, adding the "button is-fullwidth" class forces the two elements to display inline. Removing this class resolves the issue, but I want to understand if there's a way to keep the button class while achieving the desired vertical layout.

You can view a full JSFiddle where I've tried different solutions without success.

Is this behavior expected with the "button ..." class in Bulma? Is there a way to maintain the button class and still have the elements appear on separate lines?

Answer №1

The button class is being styled using flexbox, where the property display: flex makes its contents appear inline. To learn more about flexbox, you can check out this guide here and also visit this link.

There are various ways to achieve the desired layout, but here is one suggested approach:

  1. Add the .is-block modifier to a.button - This will override the display property and ensure that block elements stack properly. Alternatively, you can address this in CSS by adding flex-direction: column to your button.

  2. Instead of adjusting the height of .column with inline CSS, consider creating a new modifier class to set fixed heights as needed. For example, you could use classes like is-fixed-height and height-200 for columns, along with some custom CSS definitions.

  3. Bulma assigns a height of 2.25em to .button, which may need to be overridden with 100%. It's recommended to create a modifier class like

    is-height-100</code) or target the specific button with CSS directly, rather than relying on inline styles.</p></li>
    <li><p>If the images used are too large, making it difficult for text to fit below the buttons, instead of setting <code>height: 200px
    for the column, try using min-height. If a fixed height is necessary, adjustments might be required for the images. Feel free to reach out for assistance if needed.

View the fiddle

.is-fixed-height.height-200 {
  min-height: 200px;
}

.is-fixed-height.height-200 .button {
  height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.1/css/bulma.min.css" rel="stylesheet"/>
<div class="container">
  <div class="block">
    <div class="columns">
      <div class="column is-fixed-height height-200">
        <a class="button is-block is-fullwidth">
          <img src="https://d30y9cdsu7xlg0.cloudfront.net/png/30611-200.png" alt="">
          <p class="title">Print Release</p>
        </a>
      </div>
      <div class="column is-fixed-height height-200">
        <a class="button is-block is-fullwidth">
          <img src="https://d30y9cdsu7xlg0.cloudfront.net/png/30611-200.png" alt="">
          <p class="title">Print Release</p>
        </a>
      </div>
      <div class="column is-fixed-height height-200">
        <a class="button is-block  is-fullwidth">
          <img src="https://d30y9cdsu7xlg0.cloudfront.net/png/30611-200.png" alt="">
          <p class="title">Print Release</p>
        </a>
      </div>
    </div>
  </div>
</div>

Answer №2

You assigned the anchor an attribute of button and full-width

The attribute button will always display content inline

HTML

<a class="btn is-fullwidth" style="height: 100%">
   <p> <img src="https://d30y9cdsu7xlg0.cloudfront.net/png/30611-200.png" alt=""> </p>
   <p class="title">Print Release</p>
</a>

CSS

.btn {
text-align: center;
}

I modified the button attribute to a custom attribute name btn, then applied a center alignment using CSS

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The two Bootstrap columns are not displaying properly on the screen

I'm working on a website that features a gallery. The code below should ideally display two columns of photos when viewed on a medium device width (768px up to 992px). However, only one column is showing up on the screen. I'm hesitant to group th ...

Creating HTML using JavaScript

This particular issue has been a challenge for me despite its apparent simplicity. I have a Javascript code that is responsible for constructing elements in the DOM by utilizing JSON data from a server script. Within this code, some of the elements include ...

Navigation bar collapse items are not properly aligned in the layout

My navbar collapse button is not aligning the items in the dropdown properly. I suspect it has to do with the way I have structured the divs. How can this issue be fixed? <nav class="navbar navbar-expand-md navbar-light mb-4 row"> <b ...

Control other inputs according to the chosen option

Here is the HTML code snippet: <fieldset> <label for="tipoPre">Select prize type:</label> <select id="tipoPre"><option value="Consumer Refund">Consumer Refund</option> <option value="Accumulated Prize Ref ...

What is the best way to apply the :nth-child() selector to target every second <div> element within ALL child elements?

I'm currently developing a commenting feature, and I am in need of CSS to select every alternate child <div> (even children nested within the first set of children). Consider this example HTML structure: <body> <div class="comment"&g ...

Click on link after animation has finished

I'm currently facing an issue with my script not functioning correctly. The code I'm utilizing is from a resource provided by Codyhouse to implement a 3D rotating navigation menu on my webpage. Essentially, when you click the hamburger icon, it o ...

Using jQuery, JavaScript, and PHP, we can easily implement the functionality to disable the form and submit button

After submitting a form, I am trying to disable both the submit button and the form itself. However, every solution I have attempted either disables the form and button without submitting it or submits the form without disabling the button/form. This is t ...

Which is better for displaying HTML content: WebView or TextView?

I have a collection of html pages stored as Strings in my android application. Imagine it like this: List<String> myWebPages, where each String represents an html page containing css and javascript within the html body. What would be the most effecti ...

Problem occurs when tab links vanish after clicking on another part of the website

Exploring the world of Javascript as a newcomer has been quite an adventure, but I've encountered a hurdle with tab links on my website. Everything seems to be working fine – the links cycle through and display the correct content. However, when it ...

Is it possible to divide searches into separate divs?

How can I display the results of my AJAX live search in different result divs for styling purposes? I want to style the results separately and have them appear one at a time. However, the current setup with 'element.style' is causing issues. Is ...

Fetching the added information using ajax

Hey everyone, I have a question about reloading the appended data on my page. The page has infinite scrolling functionality and I want to reload the elements that are added when a particular element is clicked. The loading works fine for elements that were ...

photos arranged in rows rather than a single row

Looking for help with arranging the remaining photos in the second row? Check out this example image link. I'm struggling to organize a row of overflow images within the "small-img-row" division. This row is located under the main image in col-2. H ...

"Struggling with setting the default checked state for single and multiple checkboxes? The ng-init method with checkboxModel.value=true seems to be ineffective – any suggestions

<input type="checkbox" ng-model="isChecked.value" ng-true-value="'yes'" ng-false-value="'no'" ng-click='handleCheckboxChange(isChecked.value, idx);' ng-init="isChecked.value=true" /> ...

Retrieve information from a Django model in mysql based on user input

I am trying to retrieve data from a Django model (stored in MySQL) based on user input. Essentially, I have an HTML search bar where users can enter a value, which should then fetch related data from the Django model and display it on another HTML page. ...

Optimizing HTML Borders

I'm having trouble aligning the second border frame below the telephone image in a similar way to Gmail. I've tried multiple approaches but can't seem to get it right. Any assistance would be greatly appreciated :) .b1 { border: 1px s ...

Carousel With Multiple Items Displayed Simultaneously In Bootstrap

Is there a way to create a carousel with multiple items in Bootstrap 4? The documentation talks about multiple carousels, but not specifically about how to display multiple items within a carousel. ...

Loading two scripts in sequence, the first utilizing the "src" attribute while the second is an inline script

The HTML code below shows two script elements being added to the body of a webpage. <html> <body> <script> const first = document.createElement("script"); first.setAttribute("src", "./remote.js"); first.async = false; const second = doc ...

The WebView.HitTestResult method is currently only receiving <img src> elements and not <a href> elements

I am attempting to open a new window in the Android browser using "_blank". I have set up an event listener for this purpose. mWebView.getSettings().setSupportMultipleWindows(true); mWebView.setWebChromeClient(new WebChromeClient() { ...

Stop the div from collapsing when hiding or deleting all child elements to maintain its structure

I have recently developed a Vuetify application that manages card items. To ensure security and accessibility, I have added a feature where the actions/buttons are displayed based on the User's permissions. In case of missing permissions, these button ...

When a child of a flex-item does not inherit the height of its parent in a flex container with a column direction and flex-basis set

Wow, that title was long! Let me try to clarify my confusion: So I have a flex-container with 2 flex items. <!-- HTML --> <div class="container"> <div class="item-1"> <div class="child-of-item-1"></div> < ...