Alignment of button group with Bootstrap 4.0 Beta is now easier than ever

I have a <div> in Bootstrap 4.0 that I am using to display a row of buttons horizontally within the div. I have tried defining the btn-group elements as both <buttons> and <a role="button">, but no matter which way I do it, the left-most button appears misaligned:

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

When using the <a> approach, my div declaration looks like this:

<div class="btn-group btn-group-justified" id="hours-and-location">
  <a href="#" class="btn btn-secondary btn-block" role="button">button</a>
  <a href="#" class="btn btn-secondary btn-block" role="button">button</a>
  <a href="#" class="btn btn-secondary btn-block" role="button">button</a>
</div>

If I declare them as <buttons>, it looks like this:

<div class="btn-group btn-group-justified align-self-center" id="hours-and-location">
  <button type="button" class="btn btn-secondary btn-block h-100">Button 2</button>
  <button type="button" class="btn btn-secondary btn-block h-100">Button 2</button>
  <button type="button" class="btn btn-secondary btn-block h-100">Button 3</button>
</div>

I have tried adjusting margin, padding, using !important in CSS, and researching numerous CSS solutions. I have also inspected the elements in Firefox's developer tools but cannot determine why they are not aligned correctly.

I am open to any additional suggestions for resolving this issue. Ultimately, I just want some buttons to fill a div. If there is a simpler Bootstrap method to achieve this without overriding extensive CSS, I would appreciate the guidance. Thank you for your assistance.

As I write this, I realize that I forgot to include my CSS, and the problem arose even without my CSS (so I wasted time debugging CSS 😩🔫).

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

<br>
<br>
<br>
<section class="container-fluid">
  <div class="row vertical-center">
    <div class="container-fluid">
      <!-- Main jumbotron for a primary marketing message or call to action -->
      <div class="container-fluid">
        <!-- <div class="row my-auto"> -->
        <div class="row">
          <div class="col-sm-4">

          </div>
          <div class="col-sm-8">
            <div class="btn-group btn-group-justified align-self-center" id="hours-and-location">
              <button type="button" class="btn btn-secondary btn-block h-100">Button 2</button>
              <button type="button" class="btn btn-secondary btn-block h-100">Button 2</button>
              <button type="button" class="btn btn-secondary btn-block h-100">Button 3</button>
            </div>
            <!-- <div class="btn-group btn-group-justified" id="hours-and-location">
          <a href="#" class="btn btn-secondary btn-block" role="button">button</a>
          <a href="#" class="btn btn-secondary btn-block" role="button">button</a>
          <a href="#" class="btn btn-secondary btn-block" role="button">button</a>
        </div> -->
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Answer â„–1

There is an issue with the vertical alignment due to the btn-block class being used. To fix this, remove btn-block from all buttons in your code.

The purpose of btn-block is to create block-level buttons that span the full width of their parent element, causing them to stack vertically with default spacing between each button. Here is a snippet from the documentation for reference:

Create block level buttons—those that span the full width of a parent—by adding .btn-block.

bootstrap-4

In addition, the use of align-self-center on the button wrapper is incorrect as it is intended for flex items within a flexbox container. You should either apply it directly to each individual flex item or use the align-items-center class on the container itself.

Please refer to the demo below for further clarification:

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">


<br>
<br>
<br>
<section class="container-fluid">
  <div class="row vertical-center">
    <div class="container-fluid">
      <!-- Main jumbotron for a primary marketing message or call to action -->
      <div class="container-fluid">
        <!-- <div class="row my-auto"> -->
        <div class="row">
          <div class="col-sm-4">

          </div>
          <div class="col-sm-8">
            <div class="btn-group btn-group-justified align-items-center" id="hours-and-location">
              <button type="button" class="btn btn-secondary h-100">Button 1</button>
              <button type="button" class="btn btn-secondary h-100">Button 2</button>
              <button type="button" class="btn btn-secondary h-100">Button 3</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

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 link tag cannot be used inside a division element

I am facing an issue with a button that has three different states represented by images. While the button looks great and functions well, it fails to perform its primary function - linking to another document. Upon clicking the button, no action is initi ...

Dynamically align text in the center of an image, vertically

I'm trying to create a hover effect where an image and text are displayed in the center of the image when someone hovers over it. Here is how the HTML looks: <article> <div class="entry-content"> <a href="http://www.linktopost.com"> ...

Overlay sliding seamlessly with text scrolling

I just joined this platform and I'm playing around with creating an overlay that slides up with text over an image. However, I'm encountering some issues with the positioning of the overlay. This is part of a responsive gallery where all images h ...

What disparities exist between utilizing Arial Black font and regular Arial font with the <Strong> tag?

Despite setting my text to Arial Black, it appears as regular text on Firefox. To workaround this issue, I tried using the Arial font with the Strong tag but couldn't notice any visual difference. Should I be concerned about this discrepancy? Thank y ...

I have exhausted all possible solutions in my attempts to eliminate the whitespace below my footer. Is there something I have overlooked or not tried yet?

After updating the CSS stylesheet, I noticed a white space below my footer. A screenshot has been included for reference. Despite including a CSS reset, the issue still persists. /* html5doctor.com Reset Stylesheet v1.6.1 Last Updated: 2010-09-17 Author ...

The CSS form appears to be too large for the page

On every single one of my pages, the content fits perfectly within the body: However, when I have forms on the page, they extend beyond the footer and the body doesn't resize accordingly: Where could the issue be coming from? ...

Exploring the pros and cons of dividing static files on my website - What should I consider?

Currently working on a Django project and incorporating Twitter Bootstrap for the layout. My question is simple: Bootstrap offers the flexibility to choose which styles/JS to download separately - such as forms, tables, responsive design, button styles, n ...

What is the best way to calculate the width of an element that exceeds its container using javascript?

I am looking to create a WordPress plugin that can detect if any title exceeds its designated container and adjust the font size accordingly. The PHP script I have written iterates through all titles on each page and post, extracting each word and storing ...

ZeroClipboard intricate CSS issue

I have a list of images with an option box that appears on mouseover. The box contains an embedded code input field for copying purposes. I recently implemented zeroclipboard to enable the copy function on click. However, when I hover over an image and try ...

Encountering numerous challenges while attempting to create a switch theme button with the help of JavaScript's localStorage and CSS variables

It's frustrating that despite all my efforts, I'm still stuck on implementing a small feature for the past 5-6 hours. I need assistance with storing a single variable in the user's localStorage, initially set to 1. When the user clicks a but ...

Issue with margin-top on <p> and <a> elements not displaying correctly?

I've been attempting to incorporate margin-top for a link button, but unfortunately it's not working as expected. I've even experimented with inline styles for both the 'p' and 'a' tags. There are three list elements, I ...

What is the process for packaging asset folders in an Angular 4 application?

Currently, in my Angular4 App with Webpack, after executing the ng-build --prod command to build the application, I noticed that while the assets folder is present in the dist directory, the css and js files are not bundled or minified. I am seeking guida ...

Having difficulty connecting images or photos to CodePen

I've been attempting to connect images and sound files to my CodePen project using a Dropbox shared link. <div class="container"> <div class="row second-line"> <div class="col-12"> <div d ...

Incorporate a text input feature into the Pikaday modal dialogue box

I'm currently in the process of revamping Pikaday and want to swap out the year select for a text input. However, every time I add an input field, it ends up being unresponsive. Despite not being disabled, z-indexed to the background, or having any op ...

The problem with the Image Gallery carousel not functioning properly in a right-to-left direction arises when attempting to modify

I have been developing an image gallery that functions perfectly in the English version of the website. Now, I am tasked with replicating the same functionality for another version of the website that requires right-to-left (RTL) direction. However, when I ...

Ways to dynamically allocate HTML space uniformly

Struggling with CSS and HTML in my Angular application right now. Check out this overview of the setup. My goal is to create a central component (Component 1 in the design) with a button from Component 2. My HTML structure would be something like this: & ...

What is preventing the disabled attribute from being removed in the modal window?

My modal includes a feature allowing users to upload files. By default, the upload button is disabled. However, when the user inserts a file, the button should become enabled. I have attempted two different methods to resolve this issue but so far have not ...

Can a CSS rule be prevented from inheriting?

Currently, I have implemented this CSS rule in the body selector: body { text-align:center } However, it seems like this rule is inheriting down to all other text elements on the page. Is there a way to prevent CSS from applying this rule to other elem ...

Bootstrap 5 div containing footer

Struggling to achieve this in HTML using Bootstrap 5, any assistance would be greatly appreciated. https://i.sstatic.net/ghsb8.png The overall concept is clear, but encountering an issue with the initial image. https://i.sstatic.net/MOPmJ.png ...

Converting CSS into jQuery

I am exploring ways to create a collapsible section with arrow icons (right and down arrows) in jQuery or JavaScript. Can anyone provide guidance on how to convert my CSS styling into jQuery code? Below is the jQuery approach I have attempted: $(document ...