Create a responsive Bootstrap 4 button group without the need for any additional custom CSS styling

I'm currently working on a div containing a button group.

Below is the code snippet:

<div id="main"><!-- Full-width container with no padding or margin -->

    <div class="btn-toolbar" role="toolbar">
      <div class="btn-group btn-group-justified" role="group">

      <div class="btn-group" role="group">
        <button class="btn btn-primary btn-lg"><i class="fa fa-plus"></i> Add</button>
      </div>

      <div class="btn-group" role="group">
        <button class="btn btn-primary btn-lg"><i class="fa fa-download"></i> Import</button>
      </div>

      <div class="btn-group" role="group">
        <button class="btn btn-primary btn-lg"><i class="fa fa-trash"></i> Delete</button>
      </div>

      <div class="btn-group" role="group">
        <button class="btn btn-primary btn-lg"><i class="fa fa-save"></i> Save</button>
      </div>

      </div>
    </div>

</div>

The challenge I'm facing is that I need all these buttons:

1. To be of equal size 
2. To occupy 100% width in the parent div side-by-side

Currently, I can only accommodate 3 buttons but require space for 4.

One solution could involve dividing 100 by 4 to allocate button sizes accordingly. However, since I'm utilizing Bootstrap 4, I am curious if there's a way to achieve this using Bootstrap's own classes. If not, what would be the best approach to resolve this issue?

Answer №1

Feel free to include the following code snippet in your index.html file

<!doctype HTML>
<html lang="en">

<head>
<!-- Essential meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
    integrity="sha384-9aIt2nRe3js3W69CrGF8kKXvvmYtT4zNGqicXRjvuAnmmbvPZXc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="./style.css" type="text/css">
<title>WeGo</title>
</head>
<body>
<div id="main"><!-- This div is set to 100% width with no padding or margin -->

<div class="btn-toolbar" role="toolbar">
  <div class="btn-group btn-group-justified bg-primary" role="group" style="width: 100%;">
    <div class="row">
      <div class="col-lg-3 btn-group" role="group">
        <button class="btn btn-primary btn-lg" style="width: 20em;"><i class="fa fa-plus"></i> Add</button>
      </div>

      <div class="col-lg-3 btn-group" role="group">
        <button class="btn btn-primary btn-lg" style="width: 20em;"><i class="fa fa-download"></i> Import</button>
      </div>

      <div class="col-lg-3 btn-group" role="group">
        <button class="btn btn-primary btn-lg" style="width: 20em;"><i class="fa fa-trash"></i> Delete</button>
      </div>

      <div class="col-lg-3 btn-group" role="group">
        <button class="btn btn-primary btn-lg" style="width: 20em;"><i class="fa fa-save"></i> Save</button>
      </div>
    </div>

  </div>
</div>

</div>
<script src="jquery/jquery.slim.min.js"></script>
<script src="popper/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>

I trust this information will be useful for you.

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

Adjusting the size of an image based on the size of the window

I'm currently working on my first website project. I have successfully implemented a large image banner, however, I am facing an issue with setting its height. Whenever I try to adjust the height using percentage values, the banner disappears. My goal ...

Reversed Sink CSS3 Animation moving to the left side

Currently, I am working on creating an animation that gives the illusion of a div sinking backward and then being pushed to the left once it has finished falling back. Although I am using CSS3 for this project, I am not very familiar with the animation pr ...

Explore the interactive feature of hovering over a component within a div that is enhanced with a transformative translate3d effect upon hover. Discover the seamless event queuing

Within a div, there is a modal component that includes a transform: translate3d effect with hover transition. The div is created using vue.js list rendering method. Upon opening the modal and hovering over it, it jerks between the parent div and its intend ...

CSS Color-Range Conditional Styling

I am interested in creating a simple chart using divs and spans, with the goal of implementing conditional formatting on each column based on its value to determine height. I have been struggling with figuring out how to make it work similar to Excel' ...

In Safari, the scrollbar appears on top of any overlays, popups, and modals

On my webpage, I have a div with the CSS property overflow-y: scroll. The page also features several popup modals and overlays. Strangely, the scrollbar of the div appears on top of these overlays instead of behind them. I attempted to resolve this issue b ...

Is there a significant time-saving benefit to utilizing nested rules in CSS, particularly when using HAML or LESS?

Here is how I am currently coding my CSS: Regular CSS: #content { color: white; background: black; } #content a { color: yellow; } #content p { margin: 0; } #content (etc...) #contnet (etc...) #content (etc...) (I always include the parent eve ...

The final item in the Bootstrap carousel will automatically conceal the right control option

Currently utilizing bootstrap 4.0, I am seeking a solution to hide the left control on the first item and hide the right control on the last item within the carousel. I believe jQuery can assist in achieving this. The left control should be hidden at all ...

How to Create a React Material UI Switch with Minimal Padding

I need a compact Switch component without any additional dimensions or spacing Check out this custom Switch component <Switch checked={isSubscriptionStatusActive} onChange={onHandleChangeSubscriptionStatus} disabled={subscriptionStat ...

Show small information box when hovering over custom toggle button

I have developed a unique custom toggle switch feature When I hover my mouse over the switch, it should display a tooltip message as YES if the switch is in the ON position and NO if it's in the OFF position. Is there a way to implement this functio ...

Looking to add elements to a specific div dynamically using jQuery? Let's explore how to insert comments seamlessly

I would like to implement a comment system that adds entered comments to a specific div. Here's the code I have so far: <ul class="comments"> <li> <a class="commenter_name" href="/">Dushyanth Lion</a> ...

Position SVG's in relation to one another

I have two SVG's and I'm looking to position the second SVG in the top right corner of the first SVG. In this example, I want to place the exclamation SVG in the TOP RIGHT corner of the first SVG. Can someone provide guidance on what changes I n ...

Issue with Bootstrap 3 columns not arranging correctly

Utilizing Bootstrap 3, I am attempting to stack grids on top of each other in the order of A, B, C, D, E. While the mobile grid stacking works well, the issue arises when viewing it on desktop where the grids do not align as expected, particularly the box ...

What's the best way to preserve the aspect ratio of my background image while utilizing background-size: cover;?

I have a background image that I'm working with. Is there a way to preserve the aspect ratio of the image even when using background-size: cover;? Currently, the image fits perfectly on the screen but appears slightly distorted. I've experimented ...

Adaptable Layouts in Bootsrap Grid

I am currently working with Bootstrap Grid. https://i.sstatic.net/giJOI.png One issue I am facing is when I switch back to my mobile screen, I want the layout to adjust accordingly like https://i.sstatic.net/RYPJm.png I have tried different methods but ...

How can we create a stylish HTML table using CSS display:table and SASS in a sophisticated manner?

Is there a more stylish approach to styling this HTML table using CSS display: table with Sass? Instead of using traditional table elements, I have created a table layout using display: table CSS styles applied to div elements: <div style="display: ...

The enhancement of clickable link padding

I'm having an issue with the padding around the link in my dropdown menu not being clickable. The text itself works fine when I hover over it, but the surrounding padding is inactive. I tried styling it as an inline-block as suggested, but that did no ...

What is the best way to achieve a precision of 6 decimal places in JavaScript when working with decimals?

While working on coding to round numbers to six decimal places after performing some arithmetic operations, I encountered a problem. I was iterating through the elements of an array and conducting calculations based on the array contents. To achieve roundi ...

Encountering problem when attempting to incorporate fade in/fade out effect animation

I have a webpage that features multiple buttons, each triggering a fade-in/fade-out animation when clicked. This animation also involves changing the contents of a specific div. Though everything is functioning properly, there is a brief moment (about hal ...

Tips on adding style to your jQuery autocomplete dropdown

I am currently utilizing jQuery autocomplete functionality. I have configured it to communicate with a service and retrieve records: <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1 ...

Issues with CSS and JavaScript functionality persist within the Flask framework

Having trouble with CSS and JavaScript on my website hosted via Flask framework on PythonAnywhere. Here is the directory structure: home/dubspher/mysite/ - README.md - app.py - index.html Static/ - css - fonts - images - js - sass Original HTM ...