What is the best way to place a single button above a row using the bootstrap btn-group?

I currently have 11 buttons arranged in 3 rows, and I am trying to position one button at the top as a standalone element before the two rows of buttons. However, despite experimenting with various flex-end and content align classes, I have not been successful in achieving the desired layout. Below are some of the classes that I have attempted:

align-content: flex-end;
align-self: flex-end;
justify-content: flex-end;
flex-direction: row;

<div class="btn-group btn-group-toggle" data-toggle="buttons" 
id="user_skill_level"> 
... displaying the buttons here
</div>

Answer №1

To achieve the desired layout, you can combine flex-direction: row-reverse; and flex-wrap: wrap-reverse;.

Custom Styling

To avoid conflicting with the default Bootstrap styles, I have created a custom class named .btn-group-custom.

<div class="btn-group btn-group-custom">
    <button type="button" class="btn btn-primary">Button 1</button>
    <button type="button" class="btn btn-primary">Button 2</button>
    <button type="button" class="btn btn-primary">Button 3</button>
    <button type="button" class="btn btn-primary">Button 4</button>
    <button type="button" class="btn btn-primary">Button 5</button>
    <button type="button" class="btn btn-primary">Button 6</button>
    <button type="button" class="btn btn-primary">Button 7</button>
    <button type="button" class="btn btn-primary">Button 8</button>
    <button type="button" class="btn btn-primary">Button 9</button>
    <button type="button" class="btn btn-primary">Button 10</button>
    <button type="button" class="btn btn-primary">Button 11</button>
</div>

CSS Styles

.btn-group-custom {
    /* Reverse the order of wrapped items, positioning "alone" button at the top */
    flex-wrap: wrap-reverse;

    /* Display the row in reverse order to place the "alone" button on the right */
    flex-direction: row-reverse;
}

.btn-group-custom > .btn {
    /* Set width for 5 buttons in a row */
    width: 20%;
}

.btn-group-custom > .btn:first-child,
.btn-group-custom > .btn:last-child {
    border-radius: 0 !important;
}

/* Optional: add rounded corners to first and last child buttons */
.btn-group-custom > .btn:first-child {
    border-bottom-right-radius: .25rem !important;
}

.btn-group-custom > .btn:last-child {
    border-top-left-radius: .25rem !important;
}

Preview

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

View Demo: https://jsfiddle.net/davidliang2008/a3s7zno1/33/

Answer №2

To ensure the "alone" button is positioned in the center, you can follow this layout:

<div class="container">
  <div class="row">
    <button class="btn">Button A</button>
  </div>
  <div class="row">
    <button class="btn">Button B</button>
    <button class="btn">Button C</button>
    <button class="btn">Button D</button>
    <button class="btn">Button E</button>
    <button class="btn">Button F</button>
  </div>
  <div class="row">
    <button class="btn">Button G</button>
    <button class="btn">Button H</button>
    <button class="btn">Button I</button>
    <button class="btn">Button J</button>
    <button class="btn">Button K</button>
  </div>
</div>

Accompanied by the following CSS styles:

.container {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.row {
  margin: 0 auto;
}

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

Creating an input field within a basic jQuery dialog box is not possible

Can anyone assist me in adding an input box to my dialog box? I am working with jquery-ui.js. Here is the code I currently have: $(document).on("click",".savebtn",function(). { var id = $(this).attr("id"); $.dialog({ ...

Enhancing the appearance within an HTML input element

Let's consider a scenario where we have an input element with the following text: <input type="text" value="Lucas"> Is there a way to emphasize the "L" in the value as Bold, similar to Lucas? We are familiar with how this can be achieved usin ...

The functionality of AngularJS routing is malfunctioning

I'm having trouble with implementing angularJS routing on my page. Initially, it was working fine but now the browser is not returning anything. Here's the code snippet: angular.module('myRoutingApp', ['ngRoute']) .conf ...

Adjust transparency according to the information extracted from the AnalyserNode

Currently, I am exploring ways to animate text opacity based on the volume of an audio file. While browsing online, I came across this specific codepen example, which showcases a similar concept. However, as I am relatively new to JavaScript, I find it ch ...

How can one generate an array containing all attributes found in the HTML of a website?

I have a project idea where I want to be able to input a hyperlink address and then get a list of attribute contents as the output. For instance, if I input a Netflix genre hyperlink for Adventure Movies, I'd like to receive a list with all the movie ...

Verifying if a div in jQuery holds a specific element

I am currently developing drag and drop widgets using jQuery. After dropping them, I need to verify if my draggable and droppable widget is located inside another div. <div id="droptarget"> <div class="widget">I'm a widget!</div> ...

The video continues playing even after closing the modal box

I am facing an issue with my code where a video continues to play in the background even after I close the modal. Here is the code snippet: <div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria- ...

Struggling to properly position my dropdown menu without causing the div content to shift downward

<div id="header"> <a href="#" id="logo"></a> </div> <div id="nav_cont"> <ul id="nav"> <li id="main_btn"><a class="mainlink" href="#">Parent 01</a></li> <li id="communities_btn">< ...

Why does the AngularJS ngRepeat filter permanently remove null values?

Check out this JSFiddle demonstration I created to illustrate the problem: http://jsfiddle.net/s6Lj2/2/ Observe that in the dataset $scope.places = [{ name: 'Chicago', status: 'Active', analyst: 'Sam', recor ...

Ways to change specific CSS class properties in a unique style

As a Java programmer using primefaces 5.1, I've encountered some challenges with handling CSS classes. One particular issue I'm facing is the need to override certain CSS properties to remove the rounded corners of a DIV element. The rendered cod ...

JavaScript and CSS animations out of sync in terms of timing

I've been encountering some issues. I have an array containing 5 lines of text that change with a timer, but it seems that the css timer animation might not be synced properly or my @keyframes slidesdown setup could be incorrect. The delay between te ...

Use jQuery to create a price filter that dynamically sets slide values based on the filter object

I'm currently utilizing the jQuery slide filter to sort products based on price. The filtering value is set within the script, but I am interested in dynamically setting it based on the highest/lowest number found on my page using a data attribute. D ...

Is the second parameter of the function being used as a condition?

Why is it necessary to validate the helpText argument within the function to be non-equative to null when its ID is linked with the span tag? The functions task is to set and clear help messages in the form field using built-in CSS classes. <input id ...

Having trouble applying CSS to multiple classes used in an AJAX call

I'm trying to utilize richfaces for some fast AJAX widgets, but I am encountering difficulties in setting CSS parameters for them. After inspecting the generated code, I found that the elements have the classes "rf-ds" and "rpds". Despite applying st ...

Selecting and Uploading Multiple Files in Internet Explorer (less than version 9)

I have been struggling with selecting and uploading multiple files at once to the server. Here is the code I am currently using: <html> <body> <form action="upload.php" method="post" enctype="multipart/form-data" name="myForm"> <l ...

Unable to set DIV to 'inline-block' or none based on checkbox selection

Despite reviewing multiple examples, I am still struggling to make this DIV visible and hidden by clicking a checkbox. Can someone please review my JavaScript code? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Conten ...

Displaying feedback messages and redirecting in Flask may result in the response being visible in the developer tools, but

Just starting out with Flask and encountering an issue. I am trying to determine if a response is empty, and if it is, display a message. The problem lies in the fact that even though the redirect works and the subsequent GET request returns the correct HT ...

Tips for showcasing colorful XML script within an HTML text field

In the process of developing a web application utilizing Symfony, I am looking to incorporate functionality that allows users to send XML requests to remote servers. As part of the design, I have included a textarea on the page where users can input their ...

Error Message "Alexa.create is not a valid function" encountered while using the Alexa HTML Web API on the Echo Show 10

Here is the HTML code for my custom Alexa Skill. <head> <script src="https://cdn.myalexaskills.com/latest/alexa-html.js"> </script> </head> <body> var alexaClient; Alexa.create({version: '1.0'}) .t ...

Utilizing numerous copies of a single plugin

I recently integrated a plugin called flip-carousel.js into my website and here is an example of how it looks on the site. Check out the sample implementation Now, I encountered an issue when trying to use multiple instances of the same plugin. When init ...