Bootstrap grid button with maximum flexibility

I am currently exploring the intricacies of the bootstrap grid system.

My goal is to create a set of buttons that look like this:

https://i.sstatic.net/V5meG.png

Each button should expand to fill the width and height of its container.

However, when a button contains more text, it wraps onto a new line and the close button becomes misaligned as shown below: https://i.sstatic.net/6PaWN.png

Here is the code I am using :

<div class="container-fluid ">
        <div class="btn-group" style="width:100%">
            <div class="row gy-5">
                <div class="col p-2 border border-1">
                    <button class="btn-danger">Button Row 1</button>
                </div>
                <div class="col p-2 border border-1">
                    <button class="btn-danger">Button Row 1</button>
                </div>
                <div class="col p-2 border border-1">
                    <button class="btn-danger">Button Row 1</button>
                </div>
            </div>
        </div>
        <div class="btn-group" style="width:100%">
            <div class="row">
                <div class="col p-2 border border-1">
                    <button class="btn-danger">Button Row 2</button>
                </div>
                <div class="col p-2 border border-1">
                    <button class="btn-danger">Button Row 2</button>
                </div>
                <div class="col p-2 border border-1">
                    <button class="btn-danger">Button</button>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="btn-group" style="width:100%">
                <div class="row">
                    <div class="col p-2 border border-1">
                        <button>Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

I would appreciate any suggestions on how to ensure the buttons fill each box with padding, and all boxes have consistent height and width based on the largest button size.

Answer №1

If you're looking to achieve a specific layout, the code below will help you achieve it:

@import url('https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d2f2222393e393f2c3d0d78637e637c">[email protected]</a>/dist/css/bootstrap.min.css');
<div class="d-flex flex-column" style="width: fit-content">
  <div class="d-flex">
    <div class="p-2 border border-1">
      <button class="btn btn-danger">Button Row 1</button>
    </div>
    <div class="p-2 border border-1">
      <button class="btn btn-danger">Button Row 1</button>
    </div>
    <div class="p-2 border border-1">
      <button class="btn btn-danger">Button Row 1</button>
    </div>
  </div>
  <div class="d-flex">
    <div class="p-2 border border-1">
      <button class="btn btn-danger">Button Row 2</button>
    </div>
    <div class="p-2 border border-1">
      <button class="btn btn-danger">Button Row 2</button>
    </div>
    <div class="p-2 border border-1">
      <button class="btn btn-danger">Button Row 2</button>
    </div>
  </div>
  <div class="d-flex align-self-center">
    <div class="p-2 border border-1">
      <button class="btn btn-primary">Close</button>
    </div>
  </div>
</div>

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

Do you know of a more streamlined approach to formatting this SCSS code?

Currently working on a Saleor Site and diving into the world of Django and SASS for the first time. While crafting my own styling rules in SCSS files, I've noticed some repetitive code that could potentially be streamlined. It seems like there should ...

Tips for avoiding flickering in a background image when it is being changed

Utilizing JavaScript, I am setting a repeated background image from a canvas to a div in the following way: var img_canvas = document.createElement('canvas'); img_canvas.width = 16; img_canvas.height = 16; img_canvas.getContext('2d' ...

Moving object sideways in 100px intervals

I'm struggling to solve this issue. Currently, I have multiple div elements (each containing some content) that I need to drag and drop horizontally. However, I specifically want them to move in increments of 100px (meaning the left position should b ...

When using JQuery's .each method, only the first two elements from an array of automatically generated elements are retrieved

I have a loop that creates multiple divs with the class panel. @for(comment <- event.getCommentsSorted()) { However, when I try to manipulate each of these divs using jQuery's .each, only the first two divs are selected. $(window).on('load& ...

Creating a responsive table layout with CSS

I currently have the following code: .fiftyFiftySection { background-color: #000; } .odometer { font-size: 3em; text-align: center; } table td { column-width: 1000px; text-align: center; } @media (max-width: 500px) { table td { column ...

What is the correct method for inserting the following line into an XSLT document without causing it to malfunction: > data-masonry='{"percentPosition": true }' ?

Looking to implement the Bootstrap Masonry layout showcased at https://getbootstrap.com/docs/5.0/examples/masonry/ within SobiPro using Joomla 4 Cassopedia Template. Requirement for a div structure like this - <div class="row" data-masonry=&a ...

Utilize Javascript/jQuery to play individual HTML audio files sequentially

On my website, each keyboard key is associated with an audio file. When a letter key from A to Z is pressed, the corresponding audio file is played. For all other keys (excluding ESC), a random audio file out of the 26 available is played. However, if mult ...

Ajax: Why am I receiving an error response instead of a successful one?

It's puzzling why my code is triggering the error function instead of success. The console.log keeps showing me this: Object {readyState: 0, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: f ...

JavaScript combined with a dynamic menu, a customized current link style using CSS, and a site built on PHP

Here's my current website setup: My website is modular and uses dynamic inclusion. The header is a crucial part of the main page, which is responsible for displaying content from specific links on the site. External links to CSS and js files are incl ...

Geonames weather API experiencing issues retrieving data

Is there anyone who can assist in identifying why the geonames API is failing to retrieve data? Although it seems simple, it's not functioning as expected. For example, here is a link to the API: Below are the HTML/AJAX/PHP codes for review. Thank ...

When using JavaScript, links within the window.location are automatically altered

When using window.location (.assign, .replace, .href) to redirect to a product page on click, I encountered an issue where it automatically changes some of the href links. For example: instead of "previous href= 'commercial/fonts/fonts.min.css' ...

Leveraging the power of ExpressJs to incorporate a dynamic Navbar onto

ExpressJS and EJS are my chosen technologies for creating Views. When it comes to the navigation bar, I want to add a class="active" to the links that represent the current page. However, if I use partials in my views, how can I achieve this? Here is a q ...

I seem to be encountering an issue with the image tag while working with HTML code

I have been studying through freecodecamp.org and this is my first tribute project. Everything has been going well, but I am encountering an issue with the image tag. I need to submit my project online, so I have been trying to input image links from Googl ...

Loading 3D models in Three.js from the cache

Every time my page reloads, the loader loads objects from the URL instead of cache. Is there a way to check if the resource is in cache and load it directly? Appreciate your help! ...

The dropdown feature on my theme seems to be malfunctioning on Wordpress

I'm having trouble figuring out what I'm doing wrong. The dropdown navigation works fine with the default Wordpress twentyeleven theme, but when I switch to my custom theme, the dropdown stops appearing. Here is the code I'm using: <div ...

How can we incorporate interactive icons into the navigation bars on our Weebly site?

Recently, while using Weebly to design a website, I stumbled upon a webpage () that explains how to add icons to the navigation bar. Below is the code provided: /* External Fonts */ @font-face { font-family: 'dashicons'; src: url('fonts/ ...

Changing the color of an image with a click event in HTML

My coding dilemma involves two HTML codes: one displaying a table with grey square buttons, and the other featuring the same table but with orange buttons instead. I am looking for a way to change the color of the button from grey to orange when clicked, ...

Modifying an element's value according to user input: Step-by-step guide

Within my dropdown menu, there is a single option labeled "Others". Upon selecting this option, a textbox appears allowing me to input custom text. Is it possible to dynamically update the value of the <option value="Others">Others</option>, ...

Using Flask to extract data from HTML pages

Simple inquiry: I am using Flask and I need to extract the string value from this array. I am familiar with utilizing request.form["name"], but I am unsure of how to give this variable a name. How can I retrieve this variable in order to display it on my s ...

The XPath for pagination is incorrect

Whenever I try to navigate to the next page, I keep encountering an error from the robot. Can someone help me construct the xpath using either of these snippets: <li title="2" class="ant-pagination-item ant-pagination-item-2" tabind ...