Bootstrap 4 - Ensuring Tables are Mobile Responsive and Precisely Sized for Desktop viewing

Allowing users to customize table column widths in percentages that total up to 100 provides flexibility.

However, this results in cramped tables on mobile devices.

To address this issue, I aim for the table to become horizontally scrollable with the bootstrap 'table-responsive' class when viewed on mobile.

I attempted adding a class to the table columns within a mobile media query to adjust the widths, but unfortunately, this only exacerbated the cramped layout.

//css
@media (max-width: 769px) {
    .wiki-table-c-width {
        width: auto !important;
    }
  }

//example table html 

<div class ="table-responsive">
    <table class ="table table-bordered table-striped">
        <tr> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> <td class ="wiki-table-c-width" style ="width: 10%"></td> </tr>
    </table>
</div>

To summarize, custom set widths are ideal for desktop viewing, while automatic width and horizontal scrolling provide a better user experience on mobile devices.

Answer №1

If the width is set to auto, it will override any user-defined width values. To maintain the user's specified widths, you can set a fixed width for the table on mobile devices.

@media (max-width: 769px) {
    table {
        width: 769px !important;
    }
}

By implementing this solution, you can ensure that the table has a width of 769px on screens smaller than 769px. Users' intended widths will be honored, and they may need to scroll horizontally to view the entire table content.

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

Tips for implementing CSS on all descendants in Gtk3-css?

Nested Components Challenge: I have encountered an issue while attempting to add a background color to GtkComboBoxText. In my approach, I obtain the widget's context and apply CSS styling to it: * { background: red } Surprisingly, this method doe ...

Is it possible for CSS in React to cause the vanishing of all buttons

I'm encountering an issue where the CSS styling applied to every button in my NavBar is causing a specific button labeled 'Search' to disappear when it shouldn't. The problem stems from NavBar.css, which contains a media query that unin ...

CSS design issue causing icons to be cropped in material buttons

Having an issue with my button icons being cut off when using Materialize CSS with AngularJS. I've tried both Materialize icons and Font Awesome icons, but the result is the same. Check out this screenshot showing buttons with icons moved downward an ...

Is there a way to retrieve the text content from a span element using JavaScript?

Revised for better organization and explanation of the question Hello, I am new to web programming so please bear with me. My question is about extracting customer information from the following code snippet: <span class="tag-element-content" ...

Customizing div elements in various RMarkdown documents with a CSS file

I want to apply styling to divs in various RMarkdown files using a CSS file. However, I am encountering syntax issues when trying to use the external CSS file to style the div. Embedding the style tag within the rmarkdown body works as shown below: --- ti ...

Alter the hue on the fly

How can I change the color of a div based on whether it is currently red or green? I attempted the following code, but it doesn't seem to be working as expected. if ($(this).css("background-color")=="rgb(34,187,69)"|| $(this).css("background-color") ...

Skip nodes in Polymer 1.0 by using ExcludeLocalNames

I recently attempted to transition from Polymer version 0.5 to 1.0 and came across a particular question: Is there a way to exclude certain nodes inside a paper-menu? In the previous version (0.5), you could use the attribute excludedLocalNames to achieve ...

When I submit my form in Django, the data does not get added to the database

My current project involves creating a contact page for a website using Django. The goal is for clients to enter their information, which should then be submitted to the database. Even though the form is submitting without errors and the project runs smoot ...

Altering the color of a Fabulous Icon in real-time

I'm having trouble changing the color of an Awesome Icon with this code I created. Instead of getting the desired color, I am getting 'undefined' as a result. <script type="text/javascript"> function changeAIColor(idName) { alert ...

Tips on moving the first item on the Bootstrap navigation bar to the left side

I have successfully implemented a Bootstrap navigation bar and created a container to display some descriptive text beneath it, as depicted in the image provided. Utilizing the most up-to-date version of Bootstrap has ensured smooth integration. https://i ...

Creating a see-through circle going in the opposite direction with CSS

Can someone assist me with making a section on color background transparent using CSS? Below is an example of the background I'm trying to achieve: I haven't attempted anything yet because I am unsure how to do it. If I place it as a div within ...

Simple CSS inquiry regarding how to style separate occurrences of identical objects differently

When structuring my website, I often find myself in situations where I want to style identical elements differently based on their intended use. For example, I may have checkboxes that are styled using the Checkbox Hack technique and others that are tradit ...

The responsive website functions flawlessly in remote testing on Chrome, but encounters issues when live

My website gallery is responsive to all sizes when viewed on chrome at 127.0.0.1, but once I upload it to the live domain and host, the gallery appears oversized on all mobile phones. Below is the code snippet along with the CSS that I am currently using. ...

Challenges arise with the Boostrap grid system, overflow scroll functionality, and responsive design when incorporating specific heights (vh) in elements

Attempting to implement a two-column layout using Bootstrap 4 that incorporates an overflow scroll feature when the height of a parent container is specified. You can view the fiddle here: https://jsfiddle.net/zeropsi/g19kzpsh/ The challenge I'm fac ...

Picture shifting when adjusting window size

I have been attempting multiple times to prevent an image on my website from moving when resizing the window, but I have not been successful. All I want is for this image to remain in the exact same position, no matter the size of the window. The image " ...

unable to locate the nearest available table

This is my HTML code: <div id="dvUser"> <table id="tblUser" > <tbody> <tr> <td> <input class="sfCheckBox" type="checkbox" title="view" checked="checked"> </td> </tr> <tr> <td> <input class="sf ...

Using php variable to pass data to jquery and dynamically populate content in jquery dialog

I am facing challenges trying to dynamically display MySQL/PHP query data in a jQuery dialog. Essentially, I have an HTML table with MySQL results. Each table row has an icon next to its result inside an anchor tag with the corresponding MySQL ID. echo &a ...

Retrieving HTML code as a variable using Python

I am attempting to output HTML code as a variable in my Python script, but it's not working properly. What could be causing this issue? Here is an example of my code: return render_template("dashboard.html", services = "<h1>Service 1</h1> ...

What is the best way to showcase data from input fields within a bootstrap modal dialog?

After the user has entered their details and clicks submit, I would like to present the information in a Bootstrap modal with a confirmation button below. This serves as a preview of the data before it is saved to the database. Here's what I have so ...

Swapping IMG depending on breakpoint in Material-UI

I understand how to adjust styling with breakpoints for various properties like height, width, and font size. However, I am struggling to find examples of switching images based on screen sizes. My goal is to replace an image with a different one dependin ...