Tips for centering text within a button element in a table on a mobile screen

Currently using "Bootstrap-4" and facing an issue with alignment in a table. The table structure is as follows:

<div class="table-responsive">  
    <table class="table table-sm table-hover">
        <thead>
            <tr>
                <th>Item 01</th>
                <th>Item 02</th>
                <th class="col">Buttons</th>
                <th class="col-1">Item 04</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Item 01</td>
                <td>Very length column</td>
                <th class="col">
                    <div class="row no-gutters">
                        <div class="col-2">
                            <button class="btn btn-secondary btn-block">
                                -
                            </button>
                        </div>
                        <div class="col text-center quantity">
                            7 in cart
                        </div>
                        <div class="col-2">
                          <button class="btn btn-secondary btn-block">
                              +
                          </button>
                        </div>
                    </div>
                </th>
                <th class="col-1">Item 04</th>
            </tr>
        </tbody>
    </table>
</div>

The symbols like - and + within buttons are not aligned properly on smaller devices, unlike on larger screens:

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

Seeking a solution to align the signs - and + at smaller device widths(e.g.,275px):

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

Is there a way to address this alignment issue for the buttons' content on smaller devices?

Here is an example link for reference.

Answer №1

If you want to maintain alignment, simply take out the btn-block class from each <button> element. By doing this, you will eliminate the width: 100% property and prevent them from resizing on smaller screens:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="table-responsive">
  <table class="table table-sm table-hover">
    <thead>
      <tr>
        <th>Item 01</th>
        <th>Item 02</th>
        <th class="col">Buttons</th>
        <th class="col-1">Item 04</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Item 01</td>
        <td>Long column name here</td>
        <th class="col">
          <div class="row no-gutters">
            <div class="col-2">
              <button class="btn btn-secondary">-</button>
            </div>
            <div class="col text-center quantity">
              7 in cart
            </div>
            <div class="col-2">
              <button class="btn btn-secondary">+</button>
            </div>
          </div>
        </th>
        <th class="col-1">Item 04</th>
      </tr>
    </tbody>
  </table>
</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

Conceal the scroll bar while the page preloader is active

Is there a way to hide the scroll bar while the preloader is loading on a webpage? I want to prevent users from scrolling until the preloader disappears. I have tried using CSS and setting the body overflow to hidden, but it's not working as expected. ...

An issue has occurred: The column name 'B' is not valid. This error originated from the System.Data.SqlClient.SqlConnection

I'm currently working on developing a straightforward registration page using ASP.NET C# in Visual Studio 2013. After attempting to submit the registration details for database insertion purposes, an error occurred. The error message indicated an iss ...

The image component is missing the necessary "src" attribute even though a valid src value has been provided as a prop

I'm encountering an issue in Next.JS where a component is not recognizing the image source passed through a prop. I am providing the path of an image named "logo.jpg" from the project's public folder. The image successfully displays when used as ...

There seems to be an issue with the <mat-form-field> where normal input functions correctly, but encounters an error when trying to use mat

I've searched through other inquiries, but none have provided the solution I am looking for. <mat-form-field> <mat-select matInput placeholder="Favorite food"> <mat-option *ngFor="let food of foods" [value]="food.value"> ...

Cursor customized image vanishes upon clicking anywhere on the page on a MAC in various web browsers

I am currently trying to set a custom image as the cursor using jQuery in this manner $(document).ready(function(){ $("body").css('cursor','url(http://affordable-glass.com/test/penguinSm.png),auto'); }); While this method works, ...

Tips for directing attention to a specific row with an input field in JavaScript

I duplicated a table and added an input field for users to search or focus on a specific row. However, there are two issues: When a user enters a row number, the table displays the wrong row - for example, if the user enters 15, the table shows row number ...

What is the method for generating an oval shape with a border-radius in CSS?

Is there a way to create an oval shape instead of a rectangle with rounded edges using CSS? Below is the code snippet I have been working with: div { position: fixed; border-radius: 25px; background: rgba(0,0,0,.5) width: 100px; height: 50px; ...

What could be causing selenium to struggle in locating specific text on a webpage

In my webpage, I have a "tree menu" that can be opened by clicking on a button. Once the tree menu is open, I need to follow certain steps and click on different titles. For example, I would click on "19,20", then "may", and finally "2". At the top of the ...

Tips for achieving a Google Map that smoothly slides behind a sticky header as you scroll

I recently added a sticky header using CSS to my long HTML page. At the bottom of the page, there is a <div> element with a Google Map embedded in it. As I scroll down the page, the content scrolls behind the sticky header as expected, but the Googl ...

Store user inputs from HTML forms into database using Javascript

I'm looking for assistance on how to store this javascript/html form data in a database. My expertise lies in connecting html/php with SQL, and I need guidance on integrating this form submission process. Below is the code snippet that enables users ...

Creating a visually balanced footer in your webpage is essential to providing a cohesive design. Learn how to perfectly align left

Struggling to align my footer text in a straight line. As a beginner, I hope this question isn't too basic! Check it out below: https://i.sstatic.net/ZophZ.png I want those three lines to be in perfect alignment. I've been taught a grid method ...

Designing a popup using Angular, CSS, and Javascript that is capable of escaping the limitations of its parent div

I'm currently working on an Angular project that involves components nested within other components. My goal is to create a popup component that maintains the same size and position, regardless of where it's triggered from. One suggestion I rece ...

Vue JS console displays an error stating "the <li> tag is missing a closing tag."

Below is the code snippet I am currently using to change the color based on the character's name: I encountered an error indicating that the li tag was not properly closed, although it appears to be closed. However, there seems to be an issue during ...

Manually entering a date for maximum returns results in an undefined output

I am facing an issue with two datepickers in my code. When the max date is set for the From date and I manually select that exact date, it returns an invalid date. However, if I select any other date, it returns the correct value. For example, if the max d ...

Using AngularJS to Retrieve a Specific DOM Element Using its Unique Identifier

Example Please take a look at this Plunkr example. Requirement I am looking for a way to retrieve an element by its id. The provided code should be capable of applying a CSS class to any existing DOM element within the current view. This functionality ...

The functionality of Bootstrap is currently malfunctioning within the ReactJS code

I am trying to implement Bootstrap for a table in ReactJS. I have the following code where I used class="container" in the <div> and class="table table-striped" in the <table>, however, the Bootstrap styles are not being applied. Can you help m ...

Troubleshooting HTML and JavaScript

Currently grappling with a coding challenge for a website in HTML/Javascript. Managed to put together a significant portion of code that seems functional, yet the roadblock I've hit now is around handling multiple line strings within Javascript. < ...

Sending user input from a Laravel modal form to a controller as a parameter

I have a button that triggers a modal form where the user can update their group name. I'm trying to pass the ID into the form using {!! Form::open(['action' => [ 'ContactsController@update', id]]) !!}. I attempted to do this si ...

How to Properly Adjust the Material UI CircularProgress Size

Is there a way to display the Material UI CircularProgress component at a size that nearly fills the parent div, which has an unknown size? Ideally, I want the size to be around 0.8 * min(parent_height, parent_width). I've experimented with adjusting ...

In the realm of website design, the IE7 display

I am currently facing an issue with my gallery buttons when using IE7. The CSS code I have for the buttons is causing them to shift to the right hand side of the gallery, even though they work fine in other browsers. Here is the code: .prv_button{ flo ...