Creating Fully Responsive Buttons that Fill Grid Columns in Bootstrap 3

Utilizing Bootstrap, I am in the process of creating a small internal website. However, I have encountered some difficulties with a particular layout on the homepage.

The first row consists of link anchors styled as buttons. I want these buttons to all be the same width and height, wrap their text contents, and have a bold 'title' text with summary text, while ensuring that all text is vertically aligned in the middle of the button.

I have managed to set fixed width buttons and enable word wrapping. Yet, I am struggling to make all buttons the same height and to vertically align the text in the middle. Additionally, there seems to be an issue with the line break element.

HTML

<div class="container">
  <div class="row">
    <div class="col-md-2">
          <a href="#" class="btn btn-default btn-lg btn-fill" role="button">
            <strong>Button A</strong><br/>
            <span>Long Summary That's Annoyingly Long</span>
          </a>
        </div>
    <div class="col-md-2">
      <a href="#" class="btn btn-default btn-lg btn-fill" role="button">
        <strong>Button B</strong><br>
        <span>Very Long Summary</span>
      </a>
    </div>
  </div>
</div>

CSS

.btn-fill {
  width: 100%;
  white-space: normal;
}

For reference, you can view a Bootply example here.

Answer №1

To create the desired layout, you can utilize .btn-toolbar along with .btn-group-justified, though there may be slight differences in how it appears:

<div class="container">
  <div class="btn-toolbar" role="toolbar">
    <div class="btn-group btn-group-lg btn-group-justified btn-group-fill-height">
      <a href="#" class="btn btn-default" role="button">
        <strong>Part A</strong><br>
        <span>Summary</span>
      </a>
      <a href="#" class="btn btn-default" role="button">
        <strong>Part B</strong><br>
        <span>Very Long Summary</span>
      </a>
      <a href="#" class="btn btn-default" role="button">
        <strong>Part D</strong><br>
        <span>Summary</span>
      </a>
      <a href="#" class="btn btn-default" role="button">
        <strong>Part E</strong><br>
        <span>Long Summary That's Annoyingly Long</span>
      </a>
      <a href="#" class="btn btn-default" role="button">
        <strong>Part F</strong><br>
        <span>Summary</span>
      </a>
      <a href="#" class="btn btn-default" role="button">
        <strong>Part G</strong><br>
        <span>Very Long Summary</span>
      </a>
    </div>
  </div>
</div>
.btn-group-fill-height .btn { 
  white-space: normal;
}

Bootply

Answer №2

Have you considered adding "text-center" to the anchor class and trying this approach:

.btn {
    height: 170px;
}

This solution may help with the height issue you mentioned. I randomly chose the number 170, but it seemed to work well in the sample you provided.

I hope this suggestion proves 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

Display HTML in JavaScript without altering the Document Object Model

Is it possible to style a custom HTML tag called "location" without directly modifying the DOM? For instance, having <location loc-id="14" address="blah" zipcode="14" /> Would it be feasible to render it like this: <div class="location"> ...

The public link created by Github only displays the name of the repository

Hello, I am a newbie in the world of web development. After dedicating a week to practicing HTML, I decided to create a project based on my CV. However, when I attempted to host the HTML files on GitHub, I encountered an issue. Whenever I clicked on the ...

Creating a lasting choice using CSS in a TableView in JavaFx

Update: Including project (reproducible example) and final details I currently have an application that showcases a TableView populated with simple object instances (observable list) The objective is to highlight selected items (rows) in the TableView. ...

Customize the style of the title bar in a jQuery dialog

Is there a way to change the title bar color of specific jQuery dialogs without affecting all of them? I tried using the property dialogClass:"myClass" in certain dialogs, but it only changes the body of the dialog. Any suggestions would be greatly apprec ...

How to Implement the Play/Pause Button in an Angular Application

I'm working on adding a show/hide feature to the play and pause buttons for a list of tracks in Angular 7. I had some success with Angular animation initially, but encountered an issue where all buttons in my list would change state instead of just on ...

<span> creating a line break after the second sentence

Link to Code: http://jsfiddle.net/MuHvy/ Javascript: $(document).ready(function () { $(".addTag").click(function () { $('.questao').html($('.questao').html() + '&nbsp;<span contentEditable="fa ...

What could be causing a slow performance issue with simple_html_dom?

I have implemented simple_html_dom in one of my web pages to scrape information from 3 different pages and display specific content. However, this process significantly slows down the page loading time. Is there a way to optimize the performance of simple ...

The scroll bar disappears behind the div

Hello, I am looking to create an HTML layout similar to the one shown below: +----------------------+-----+ | upSide | | |----------------------| | | |right| | |side | | ...

What's the best way to retrieve the nth row of a div once the mouse hovers over

$(document).ready(function() { $('div').on('mouseover', function() { alert($('div:eq(' + this + ')')); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></ ...

Is it possible for me to insert a scope into the filter as well?

Recently, I created a task filter and I am facing an issue with editing the title text when another button is selected. I attempted to use a scope but that solution did not work. Does anyone have any suggestions or alternative solutions if the scope method ...

What is the best way to send data to a child component in Angular, including components that can be

There are two components in my project: the parent component and the child component, each with their own unique markup. It is crucial for this example that the child component fetches its own data to render and not be provided by the parent. Currently, th ...

iCloud Web Portal - Element Search Failed: Element Not Found

Exploring Python as a novice, I embarked on a project that requires logging into Gmail and iCloud using Selenium. The Gmail portion went smoothly, indicating that I am headed in the right direction. However, I hit a roadblock while trying to identify the l ...

Using the Requests library in Python to transmit POST data

I am encountering difficulties sending POST data to access my account using the requests library in Python. The resulting soup remains unchanged as if no POST request was made. Here is the code I have been utilizing, which previously worked on a different ...

What sets apart the process of Installing Bootstrap with incorporating its suggested files into an HTML document?

As a novice in the world of web development, I find myself grappling with confusion. My current learning endeavor involves delving into Bootsrap through a project centered around developing a portfolio using both Bootstrap and Sass. However, an issue has a ...

Create a roulette wheel by leveraging the power of jQuery and incorporating CSS3 rotation

Currently, I am in the process of creating a mouse-controlled roulette without using canvas or SVG. Instead, I am relying solely on CSS3 rotation and some jQuery. My goal is to allow users to rotate the wheel by moving their mouse up and down while clicki ...

How can I extract a substring from a URL and then save it to the clipboard?

Hi there! I'm working on a project for my school and could really use your expertise. I need help extracting a substring from a URL, like this one: URL = https://www.example.com/blah/blah&code=12432 The substring is: 12432 I also want to display ...

Adjusting the code in Java and PHP

I'm trying to update this code because it was originally designed for .asp files, but now my document is in .php However, the script is causing some issues for me. What I really want to do is calculate how many days have passed since March 21st, 1858 ...

Applying ng-class based on conditions to icons within table cells

In my table, I am using ng-repeat to bind cells with data. One cell contains edit, save, and delete icons. When an order is posted, the delete/save icons should be disabled and displayed in a different color. While I can disable the click event of the icon ...

Python Ordering menu items for the Pelican restaurant

In response to jcollado's advice on this thread, I have set up my menu as per his instructions. However, I am facing difficulty adding the active CSS to the active item. DISPLAY_PAGES_ON_MENU = False DISPLAY_CATEGORIES_ON_MENU = False MENUITEMS = ( ( ...

The Python CGI script fails to run

While working on a simple python project with an HTML file, I stumbled upon a helpful tutorial that outlined how to execute the code. Check out the provided HTML code snippet: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html ...