How to maintain the side padding of a table within a Bootstrap 4 card?

JSFiddle: Click Here

In my design, I have a table within a card element. However, when the window size is reduced to mimic a mobile device, the left padding remains intact while the right padding disappears. How can I ensure that the right side padding is maintained within the card for smaller screens?

<div class="row">
    <div class="col-lg-8 offset-lg-2 pt-4">
        <div id="accordion">
            <div class="card mb-4">
                <div class="card-header" id="headingOne">
                    <h5 class="mb-0">
                        <button
                            class="btn btn-link"
                            data-toggle="collapse"
                            data-target="#collapseOne"
                            aria-expanded="true"
                            aria-controls="collapseOne"
                        >
                            Card
                        </button>
                    </h5>
                </div>

                <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
                    <div class="card-body table-responsive">
                        <table class="table table-bordered table-striped table-sm text-center">
                            <thead>
                                <tr>
                                    <th>Column One</th>
                                    <th>Column Two</th>
                                    <th>Column Three</th>
                                    <th>Column Four</th>
                                    <th>Column Five</th>
                                    <th>Column Six</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>Value One</td>
                                    <td>Value Two</td>
                                    <td>Value Three</td>
                                    <td>Value Four</td>
                                    <td>Value Five</td>
                                    <td>Value Six</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Answer №1

Simply relocate the .table-responsive from inside the .card-body to its own separate <div>.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
    <div class="col-lg-8 offset-lg-2 pt-4">
        <div id="accordion">
            <div class="card mb-4">
                <div class="card-header" id="headingOne">
                    <h5 class="mb-0">
                        <button
                            class="btn btn-link"
                            data-toggle="collapse"
                            data-target="#collapseOne"
                            aria-expanded="true"
                            aria-controls="collapseOne"
                        >
                            Card
                        </button>
                    </h5>
                </div>

                <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
                    <div class="card-body">
                      <div class="table-responsive">
                        <table class="table table-bordered table-striped table-sm text-center">
                            <thead>
                                <tr>
                                    <th>Column One</th>
                                    <th>Column Two</th>
                                    <th>Column Three</th>
                                    <th>Column Four</th>
                                    <th>Column Five</th>
                                    <th>Column Six</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>Value One</td>
                                    <td>Value Two</td>
                                    <td>Value Three</td>
                                    <td>Value Four</td>
                                    <td>Value Five</td>
                                    <td>Value Six</td>
                                </tr>
                            </tbody>
                        </table>
                      </div>
                    </div>
                </div>
            </div>
        </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

Having trouble getting JavaScript to select a stylesheet based on time?

I am attempting to implement two different styles based on the time of day. Here is the code I am using to select the CSS file depending on the current time: <script type="text/javascript"> function setTimedStylesheet() { var currentTim ...

What is a simple way to center a box on a page without relying on margins?

I'm attempting to position a box in the center of the page without relying on margin. Here's what I've tried so far: .box-middle { vertical-align:middle; height:100px; width:100px; border:1px solid #ddd; } This approach h ...

Achieving perfect alignment of an iframe on a webpage

Having an issue with aligning the iframe on my website. I have two buttons set up as onclick events that connect to internal pages displaying PHP data in tables within the iframe. Despite trying various CSS styles and positioning methods, I can't seem ...

Safari-exclusive bug: jQuery offset() function malfunctioning and producing highly inaccurate results

My goal is to retrieve the top offset values of a series of elements on my webpage. I am cycling through each element and recording its top offset value like this: $(elements).each(function() { var element = $(this); var offset = Math.floor($(elem ...

Revise the design of the bootstrap-multiselect interface

I am currently utilizing the bootstrap-multiselect plugin for filtering options, which can be found at https://github.com/davidstutz/bootstrap-multiselect. Everything is functioning correctly except for one issue. My dropdown menu contains approximately 80 ...

Guide to applying conditional styling to Material-UI TextField

After creating a custom MUI TextField, I implemented the following styling: const CustomDisableInput = styled(TextField)(() => ({ ".MuiInputBase-input.Mui-disabled": { WebkitTextFillColor: "#000", color: "#00 ...

Firefox not displaying caret in Bootstrap dropdown

I am trying to display a caret on the right side of a bootstrap dropdown button inside a button-group. Here is the code snippet I am using: <div class="span3 well"> <div class="btn-group btn-block"> <a class="btn btn-primary dro ...

Is there a way to attach HTML buttons to the bottom of their respective cards?

I am currently in the process of creating a directory website. To build it, I chose the Jekyll Moonwalk theme as a solid foundation and am customizing it heavily to suit my requirements. Since this is my inaugural website project, I'm learning as I p ...

Can you explain the purpose of including text-rendering: optimizeLegibility in a CSS stylesheet?

Can you explain the significance of setting text-rendering to optimizeLegibility in a CSS file? For example, like this: html { text-rendering: optimizeLegibility; } ...

Create a dynamic effect by adding space between two texts on the page

const Button = () => { const options = ['test1', 'test2', 'test3']; return ( <div style={{ position: 'absolute', left: '8px', width: 'auto', flexDirection: 'row' ...

Position Bootstrap buttons to the right side

I am looking to reposition the buttons in the header, shifting them from the default right side to the left side. Specifically, I want to move Abcd to the right side and have A1, A2, A3, A4, and A5 displayed on the left side. Here is my current code: < ...

Change the element's color to match the default anchor link

Can CSS be utilized to match an element's color with the default <a> color? If affirmative, what is the method? ...

Tips for adjusting the maximum width and content-based width for columns within an HTML/CSS table

I'm working on a simple HTML/CSS code featuring a container with two adjustable slots, controlled by a handler in the middle to modify the space each slot occupies. The first slot contains a table with fixed columns, automatic columns, and limited col ...

A white background emerges when I select md-dropdown

Lately, I've been experiencing an issue on my website where a white background pops up whenever I click on a dropdown (md-select) in my form. Initially, it only happened with forms inside a modal, but now it's affecting dropdowns across the entir ...

Trimming text from the start and inserting ellipsis in a multi-line passage

My goal is to present a paragraph on the webpage that will be dynamically updated based on user actions. I want to restrict the content to a specified number of lines and if the user tries to exceed this limit, the beginning of the paragraph should be trun ...

I am searching for a way to apply a conditional class to the chosen element in react, as the toggle method does not

I'm working on customizing a dropdown menu and I want to add a functionality where if a parent li menu has an arrow class before the ul element, then clicking on that parent li menu will add a class called showMenu only to that specific sub-menu. Her ...

Two-column list using XSLT

I am seeking assistance with xsl transformation. The xml generated by SharePoint Server control is as follows: <rows> <row>A</row> <row>B</row> <row>C</row> <row>D</row> <row>E ...

Adjustable design and content containment

Currently, I am exploring ways to utilize CSS in order to control the layout of my website effectively. My goal is to have the main frame of the website contain and confine all content within it. However, since I have not written any code yet, allow me to ...

How can I stop a character from showing up as an emoji in CSS using the 'before' and 'content' attributes?

My iPhone is displaying the character ✅︎ as a green checkbox instead of a standard grayscale thick check mark. I have already come across this question and I am familiar with the technique of adding the invisible special character \FE0E afterward ...

Problem with stacking order in Internet Explorer 7

Our current issue involves a z-index problem with a div that should be positioned above another specific div. The div in question, named (house-over-banner), is set to absolute positioning, while the one below it is relative. Interestingly, everything dis ...