Ensuring consistent readability in Bootstrap 4 by wrapping text without affecting the height

Referenced from: Twitter Bootstrap Button Text Word Wrap

Is there a way to adjust the word wrap of text inside a button in bootstrap 4 without changing the height, or maintaining equal height for all buttons? For example:

<div class="container">
    <div class="row">

    <div class="col-sm">
    <button id="1" type="button" class="btn spectral btn-secondary btn-block cbb ">General Options</button>
    </div>

       <div class="col-sm">
    <button id="2" type="button" class="btn spectral btn-secondary btn-block cbb">1</button>
    </div>


       <div class="col-sm">
    <button id="4" type="button" class="btn spectral btn-secondary btn-block cbb">2</button>
    </div>

        <div class="col-sm">
    <button id="5" type="button" class="btn spectral btn-secondary btn-block cbb ">3</button>
    </div>

       <div class="col-sm">
    <button id="6" type="button" class="btn spectral btn-secondary btn-block cbb">Nationality Change</button>
    </div>

    </div><br />


            <div class="row">

           <div class="col-sm">
    <button id="7" type="button" class="btn spectral btn-secondary btn-block cbb">4</button>
    </div>

    <div class="col-sm">
    <button id="9" type="button" class="btn spectral btn-secondary btn-block cbb ">5</button>
    </div>


       <div class="col-sm">
    <button id="11" type="button" class="btn spectral btn-secondary btn-block cbb">6</button>
    </div>

       <div class="col-sm">
    <button id="12" type="button" class="btn spectral btn-secondary btn-block cbb">7</button>
    </div>

           <div class="col-sm">
    <button id="10" type="button" class="btn spectral btn-danger btn-block cbb">Create Item</button>
    </div>

    </div>
</div>

Display result image can be found here: https://i.sstatic.net/0nDNu.png

The solution provided in multiple locations is:

.btn{
    white-space:normal !important;
    word-wrap: break-word; 
}

However, the desired outcome is to have "Nationality Change" aligned properly.

Answer №1

When utilizing BS 4, the col-* elements are automatically stretched as flex items by default. To ensure the button fills the height, simply apply height:100% to the button.

.btn {
 height:100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<div class="container">
    <div class="row">

    <div class="col-sm">
    <button id="1" type="button" class="btn spectral btn-secondary btn-block cbb ">General Options</button>
    </div>

       <div class="col-sm">
    <button id="2" type="button" class="btn spectral btn-secondary btn-block cbb">1</button>
    </div>


       <div class="col-sm">
    <button id="4" type="button" class="btn spectral btn-secondary  btn-block cbb">2</button>
    </div>

        <div class="col-sm">
    <button id="5" type="button" class="btn spectral btn-secondary  btn-block cbb ">3</button>
    </div>

       <div class="col-sm">
    <button id="6" type="button" class="btn spectral btn-secondary btn-block cbb">Change of Nationality</button>
    </div>

    </div><br />


            <div class="row">

           <div class="col-sm">
    <button id="7" type="button" class="btn spectral btn-secondary  btn-block cbb">4</button>
    </div>

    <div class="col-sm">
    <button id="9" type="button" class="btn spectral btn-secondary  btn-block cbb ">5</button>
    </div>


       <div class="col-sm">
    <button id="11" type="button" class="btn spectral btn-secondary  btn-block cbb">6</button>
    </div>

       <div class="col-sm">
    <button id="12" type="button" class="btn spectral btn-secondary  btn-block cbb">7</button>
    </div>

           <div class="col-sm">
    <button id="10" type="button" class="btn spectral btn-danger  btn-block cbb">Create Item</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

How can I capture the ng-click event in AngularJS when using bootstrap-select for styled select inputs?

After selecting an option, I am facing an issue where I cannot capture the ng-click event when a user chooses a value from the drop-down menu. This is because the select option has been altered by bootstrap-select, as the default select option does not sup ...

Troubleshooting: Navbar dropdown menu in AngularJS gets hidden within UI layout

After spending some time trying to understand why the NavBar drop-down is getting overlapped inside the ui-layout, I realize that I must be overlooking some basic steps. This issue seems so simple, yet it is eluding me. To see the details of the problem, ...

Unique content on a web page when it is loaded with HTML

Is there a way to dynamically load various content (such as <img> and <a>) into divs every time a page is loaded? I've seen websites with dynamic or rotating banners that display different content either at set intervals or when the page ...

JavaScript and HTML have encountered an Uncaught TypeError: The property 'addEventListener' cannot be read because it is null

Having an issue here. Whenever I try to play sound from an image, I encounter an error. Uncaught TypeError: Cannot read property 'addEventListener' of null Here is my HTML code: <html> <head> <title>Music</title> < ...

Displaying a static image on an HTML5 canvas without any movement

As a novice in canvas game development, I must apologize for my lack of knowledge. I have an image with dimensions 2048px width and 1536px height that needs to be placed within a canvas (the width and height vary on different devices). While I am able to ...

Bootstrap is having trouble with aligning flex items and preventing them from wrapping to a new row

I am working on a code implementation that dynamically displays flex items, with each item taking up half of the display width. So, after two items, I need to start a new row. Is there a way to add a line break after every two items displayed on the page ...

Browsing a container with JavaScript

I am attempting to display one div at a time and scroll through them repeatedly. I found and modified a Fiddle that works as intended, but when I try to implement it on my own test page, the divs do not scroll as expected. Here is the Fiddle example: http ...

Tips for dividing a div into percentages while maintaining a constant width for a div on the left side

I need help with creating a layout that involves 4 boxes. The first box (box1) should have a width of 50px on the left side, while the remaining 3 boxes should fill in the rest of the screen and be resizable. Can someone guide me on achieving this layout? ...

A guide on revealing the Inspect tab in Figma

I accessed a figma layout. enter image description here However, the Inspect tab is missing on the right side of the Design and Prototype tabs. How can I make it visible? I am in need of assistance with the Figma interface. Additional content... ...

What is the best way to implement a responsive layout in Bootstrap 5?

<body> <header> <nav class="navbar navbar-expand-md navbar-light" style="background-color:#f6b319"> <div class="container-fluid"> <div class="navba ...

Error Alert: jQuery Ajax Not Executing

Looking to send form data to PHP using jQuery. Check out the code below. -------------HTML FORM-------------- <div id="createQuestionBlock"> <form id="createQuestionForm" action="" method="POST"> Question Code: <input id="code" ...

"Encountering a Javascript issue while trying to apply a CSS class to a

Encountering issues in Safari desktop / mobile and Internet Explorer. The error message states: In Safari: TypeError: Attempted to assign to readonly property. IE Edge: Assignment to read-only properties is not allowed in strict mode The problem arises ...

highlight the selected option in the ng-repeat list of items

Looking for some assistance with a coding problem I'm having. I keep running into an error when trying to make a selected item in an ng-repeat list highlight. The CSS style is only applied on the second click, not the first. Additionally, I need to en ...

Retrieve the HTML tag content as a string using jQuery

For my OSINT project, I am developing a tool that needs to extract text from a specific HTML code string. $("p").text(); I'm looking for a way to make my variable work with the above code. Any suggestions? Share your ideas! Solution: $.ajax({ ...

A plethora of color choices in a Multi-select Box

Hi there! I am facing an issue with dynamically adding multiple select boxes. Currently, I have 4 color-coded options under the selection boxes, which work fine when there is only one box. However, when I add more than one select box, the color coding doe ...

Is there a way to align all the values in the center of the row, while ensuring that the div above the row does not have the same width as the row below it? If so, how

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> <script src= ...

Guide on displaying the name attribute of a button along with its price in a separate div when clicked

Upon clicking the Koala button, I want to display a message showing the id name of the button and the corresponding price for Koalas. Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <link h ...

Move the button above a hyperlink in a Bootstrap carousel

Is there a way to add a top-right button on each slide that will be positioned over the carousel-control link? How can I achieve this design? Currently, the buttons appear under the carousel-control as shown below: .myButton { position: absolute; ...

Decode JSON data retrieved from a remote URL address

I am in need of assistance decoding this JSON code from a URL page. The JSON code on the URL is in the following format: {"current":{"artists_id":"55","albums_id":null,"albums_tracks_id":null},"html_current":"<li><p>Pr\u00e1v\u011b h ...

Bootstrap does not control the text family, weight, and line height

Currently, I am practicing adding grid layouts using Bootstrap. I have been trying to change the font styling within my project, but unfortunately, none of the changes seem to be taking effect. It's quite frustrating because even though I'm follo ...