Issue with Bootstrap Table Column Width Not Adjusting as Expected

Table columns are not adjusting width properly with the table-responsive class.

I want to specify the width of the column containing Well Type to be 200px.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div class="table-responsive">
        <table class="table table-bordered">
          <tbody>
            <tr>
              <th></th>
              <th></th>
              <th width="200" style="width:200px;"></th>
              <th></th>
              <th></th>
              <th></th>
              <th class="text-center" colspan="2">Issue</th>
              <th class="text-center" colspan="2">Inactive Category</th>
              <th class="text-center" colspan="3">Action Steps</th>
              <th></th>
              <th class="text-center" colspan="2">Validation</th>
              <th class="text-center" colspan="2">Approved</th>
              <th></th>
              <th></th>
              <th></th>
              <th></th>
              <th></th>
              <th></th>
            </tr>
            <tr>
              <th>Well Number</th>
              <th>String Value</th>
              <th>Well Type</th>
              <th>Reservoir</th>
              <th>Downtime Start/Rig Release</th>
              <th>Downtime (in days)</th>
              <th>Code</th>
              <th>Description</th>
              <th>Code</th>
              <th>Description</th>
              <th>Code</th>
              <th>Description</th>
              <th>Planned Date</th>
              <th>Expected Rate</th>
              <th>Status</th>
              <th>Remarks</th>
              <th>Status</th>
              <th>Remarks</th>
              <th>Action Category</th>
              <th>Project</th>
              <th>Case ID</th>
              <th>Attachments</th>
              <th>Remarks</th>
              <th></th>
            </tr>
          </tbody>
          <tbody>
            <tr>
              <td>Well Number</td>
              <td>String Value</td>
              <td>Well Type</td>
              <td>Reservoir</td>
              <td>Downtime Start/Rig Release</td>
              <td>Downtime (in days)</td>
              <td>Code</td>
              <td>Description</td>
              <td>Code</td>
              <td>Incident Description</td>
              <td>Code</td>
              <td>Description</td>
              <td>Planned Date</td>
              <td>Expected Rate</td>
              <td>Status</td>
              <td>Comments</td>
              <td>State</td>
              <td>Notes</td>
              <td>Category</td>
              <td>Project Name</td>
              <td>Case Title</td>
              <td>Attachments</td>
              <td>Review Summary</td>
              <td>
                <a href="#">Edit</a>
                <a href="#">Cancel</a>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

Answer №1

To solve the issue, it is recommended to use the min-width property instead of width, as shown in the example below.

Please take note that the width attribute of <th> is not supported in HTML5 and should no longer be utilized.

Regarding your concern: Most browsers adopt an automatic table layout algorithm based on the information provided in the table-layout documentation. This could explain why your CSS settings are overridden when the table becomes too wide.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div class="table-responsive">
        <table class="table table-bordered">
          <tbody>
            <tr>
              <th></th>
               <!-- Table Header Cells Omitted for Brevity -->
              <th></th>
            </tr>
            <tr>
              <td>Cell Content Goes Here</td>
              <!-- Table Data Cells Omitted for Brevity -->
                <td>
                  <a href="#">Edit</a>
                  <a href="#">Cancel</a>
                </td>
            </tr>
          </tbody>
        </table>
      </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

How to Make a Doughnut Chart Using CSS

For a while now, I've been working on filling in 72% of a circle with a hole cut out of the middle. Throughout this process, I have been consulting different resources - like this method for calculating and this one for other aspects. However, I’ve ...

What is the best way to change the date format of a JSON string to a custom format?

Hello, I am seeking advice on how to convert a JSON string date from a response into the format of "8/24/2016". I attempted to use a dateFilter.js file, but encountered errors. Here is my attempted code: Below is the dateFilter.js code that resulted in an ...

What is the reason behind text underline being disabled when using "hidden: overflow" in CSS?

I have a long text string that I want to auto-shorten using CSS with text-overflow: ellipsis, but it's removing the underline from my link. Here is the code: NORMAL .link { font-weight: bold; cursor: pointer; color: black; text-decorat ...

Incorporating CSS into an HTML document with Jersey/Grizzly

This is the structure of my project: src/main/java -- main.java src/main/resources -- webapp -- -- css -- -- js -- -- images -- -- pages -- -- -- home.html Currently, my Maven project utilizes Jersey and Grizzly. I am able to call my REST services and lo ...

What is the process for modifying the heading color in Bootstrap's dark mode?

If you want to enable dark mode according to the Bootstrap documentation instructions, follow these steps: <html lang="en" data-bs-theme="dark"> <head> <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel= ...

Set the text to be centered and aligned to the left margin in an HTML document

After creating a bullet-point list in HTML, I centered the text and bullet points. However, when I center the text, the bullet points become staggered. Is there a way to keep the text in a straight line on the left while still centering it? https://i.ssta ...

Check if the data-indices of several div elements are in sequential order using a jQuery function

Is there a way to implement a function in jQuery-ui that checks the order of div elements with data-index when a submit button is pressed? I have set up a sortable feature using jQuery-ui, allowing users to rearrange the order of the divs. Here is an exam ...

Endless stream of text flowing in a continuous line within each paragraph

I am trying to create a unique scrolling effect for each line in a paragraph. The goal is to have each line repeat after one scroll is completed. For example: Let's say there is a line like this in the paragraph: 1,2,3,4, The desired outcome is for ...

The reverse lookup for 'about_us' with the specified arguments '()' was not found. Only one pattern was attempted: 'about_us/(?P<pk>[0-9]+)'

I am facing an issue while trying to access a blog post within the user module that has been posted by another user module. Here is my model: class details(models.Model): about_us = models.TextField(max_length=255) def __str__(self): retur ...

The IntroJs step is only partially visible on the screen

Currently, I am incorporating introJS into my application and encountering an issue where one of the steps is only partially visible on the screen. Despite trying various position settings such as auto, left, right, etc., this particular item consistentl ...

What is the best way to incorporate a website logo: using the <img> tag

As I work on building a practice website, I've noticed that I have an IMG tag for the website logo on every HTML subpage. I'm wondering if it would be more efficient to use a background image in CSS instead of the IMG tag? <div id="logo_w ...

Animated collapse with margin effect in Material-UI

I have been utilizing the MUI-Collapse component to display collapsible content within a list. I am looking to add vertical spacing between the Collapse components in the list, but I do not want the spacing to remain when the Collapse is collapsed. I am ha ...

Experiencing issues with connecting to jQuery in an external JavaScript file

My jQuery formatting in the HTML file looks like this: <!doctype html> <html lang="en"> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script> </head> < ...

Is there a way for my website visitors to seamlessly download the font I use if it's not already installed on their devices?

I've chosen the unique font ff-clifford-eighteen-web-pro-1 for my website. I'm looking to ensure that all text is consistently displayed in this font, even for users who may not have it downloaded on their device. Is there a way to make this hap ...

Insert a new, unique div onto an HTML webpage using JavaScript, ensuring no duplicates are created

Having an issue with this code snippet where nothing is being added. It seems like the variable result may not be taking a number or something else, but I'm not entirely sure why. $(document).ready(function () //document.getElementById(1).style. ...

Achieving Text Wrapping Around Unconventional Shapes Using CSS

I'm currently facing a challenge in getting text to wrap around an irregular shape on a web page. Despite numerous attempts, I have yet to find a solution that meets my requirements. Attached is an image illustrating the layout I am aiming for. The ...

Importing CSS files from node_modules in JavaScript modules can lead to CSS class names becoming "undefined" in the generated HTML

After successfully importing CSS/SCSS files into my React modules using Parcel, I encountered an issue when trying to import a CSS file from a node_modules package like bootstrap: import * as styles from 'bootstrap/dist/css/bootstrap.css'; .... ...

Adjust the increment value for ngRepeat

My current HTML template uses ngRepeat to display tiles on the page. <div ng-repeat="product in productList"> <div class="product-tile"> Product content is displayed here... </div> </div> Now, the designer requires ...

"Communication + AngularJS + Social Networking - The Perfect Trio

I'm currently in the process of developing an Angular app that will eventually be compiled using PhoneGap for both Android and iOS platforms. While testing various plugins to incorporate Facebook integration (specifically for login and sharing), I enc ...

Techniques on how to activate checkbox modification through card clicks

Is it possible to toggle the checkbox value by clicking on a card? <input id="{{a.switchID}}" name="value1" style="display:none;" type="checkbox" ng-click="send(a.deviceID,a.pinNumber,a.switchID,value1)" ng-model="value1" ng-true-value="1" ng-false-v ...