Changing the width of an HTML table does not produce any noticeable results

I attempted to create a striped table with 5 columns.

The desired column sizes are:

10% width --- 10% width --- 40% width --- 20% width --- 20% width

However, my current code is not achieving the correct widths (the 'description' column does not appear as 40% width).

https://i.stack.imgur.com/mGRgS.png

Could someone provide guidance on what might be incorrect here?

Here is the code I am using:

 <div class="row">
            <div class="col-md-12">
              <div class="panel panel2">
                  <div class="table-responsive">
                   
                   
                    <table id="dtBasicExample" class="table table-striped table-bordered" cellspacing="0" width: auto !important;  >
                   
                   
                      <thead>
                        <tr>
                          <th width="10%">ID
                          </th>
                          <th width="10%">File
                          </th>
                          <th width="40%">Description
                          </th>
                          <th width="20%">Date</th>
                          <th width="20%">Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php  
                        $data = mysqli_query($sql_con,"SELECT * FROM noticeboard");
                        while ($row = mysqli_fetch_array($data)) {
                         ?>
                        <tr>
                          <td style="width:10%;"><?php echo $row['id']; ?></td>
                          <td>
                          <?php 
                          $file = $row['file'];

                          $filetype = strtolower(pathinfo($file,PATHINFO_EXTENSION));
                            if ($filetype =="jpg" || $filetype =="png" || $filetype =="jpeg") {
                                echo "<a href = '$file' target='_blank'><i class='far fa-file-image file-icons' style='font-size:50px; color: #333'></i></a>";
                            }
                            else if($filetype =="docx" || $filetype =="doc"){
                              echo "<a href = '$file' target='_blank'><i class='far fa-file-word file-icons' style='font-size:50px; color: #333'></i></a>";
                            }
                            else{
                              echo "<a href = '$file' target='_blank'><i class='far fa-file-pdf file-icons' style='font-size:50px; color: #333'></i></a>"; 
                            }
                          ?>  
                          </td>
                          <td><span><?php echo $row['notice_desc']; ?></span></td>
                          <td><?php echo $row['ndatetime']; ?></td>
                          <td>
                            <a href="update_noticeboard.php?value=<?php echo $row['id'] ?>" class="btn btn-outline-primary btn-rounded"><i class="fa fa-edit"></i></a>
                            <a href="" class="btn btn-outline-danger btn-rounded" data-toggle = "modal" data-target= "#exampleModaldep<?php echo $row['id'];?>"><i class="fa fa-trash"></i></a>

                            <!-- MODEL -->
                          <div class="modal fade" id="exampleModaldep<?php echo $row['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                          <div class="modal-dialog" role="document">
                            <div class="modal-content">
                              <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLabel">Delete File</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                  <span aria-hidden="true">&times;</span>
                                </button>
                              </div>
                              <div class="modal-body">
                                Do you really want to delete this file?
                              </div>
                              <div class="modal-footer">
                                <a href="delete_noticeboard.php?value=<?php echo $row['id'] ?>" class="btn btn-outline-primary btn-rounded">YES</a>
                                <button type="button" class="btn btn-outline-danger btn-rounded" data-dismiss="modal">NO</button>
                              </div>
                            </div>
                          </div>
                        </div>
                          </td>
                        </tr>
                        <?php } ?>
                      </tbody>
                    </table>
          </div>
        </div>
      </div>
    </div>
        <!-- content-wrapper ends -->

Answer №1

Here are a few things to consider checking (listed from most to least likely, in my opinion):

  1. The text lines within the column may not be breaking correctly, causing the column to extend beyond its intended width. Have you applied white-space: nowrap; to the cells/paragraphs/rows/columns?
  2. It's possible that the viewport is wider than the screen, although this seems unlikely since other columns display correctly. Have you specified a width property for the table or parent elements?
  3. There could be a CSS style preventing the third column from getting the proper width. Check for any CSS rules related to column widths, such as :nth-child or :nth-last-of-type, or perhaps a media query?
  4. Consider if there is a JavaScript rule applying styles on page load, after a timeout, or triggered by other actions like clicks or changes.

Based on the image provided, it appears that the issue might be related to the first point mentioned, as the lines do not break as expected. However, without seeing the full code, these are just educated guesses.

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

Displaying the outcome of an HTML form submission on the current page

Within the navigation bar, I have included the following form code: <form id="form"> <p> <label for="textarea"></label> <textarea name="textarea" id="textarea" cols="100" rows="5"> ...

"Using jQuery to Access a View: A Step-by-Step Guide

Let's consider a scenario where I have two different views. <?php if($_GET['view']=="happy"){?> <div><p>I am feeling happy</p></div> <?php } ?> <?php if($_GET['view']=="sad"){?> <div&g ...

What is the best way to show the totals on a calculator screen?

As part of my work, I created a calculator to help potential clients determine their potential savings. Everything seems to be working fine, except for the total fees not appearing for all the boxes. I believe I might be missing the correct process to add ...

Bootstrap - placement of label to the left of the checkbox

Here is an example of a checkbox I am working with: <div class="form-check"> <input class="form-check-input" type="checkbox" value="" id="defaultCheck1"> <label class="form-check-label" for="defaultCheck1"> Default checkbox < ...

Update the displayed locations on Google Maps by fetching and displaying marker data

I am able to retrieve and display information from my MySQL table, but I need assistance with refreshing this data every 5 seconds using my current code. The data being shown is not extensive, just about 5 or 8 markers at a time. Below is the code I curren ...

Extract the last word from the URL and remove any unnecessary components

Big shoutout to the amazing individuals who have provided assistance on another thread: Retrieve final word from URL following a forward slash in PHP Now, I am encountering a new dilemma. How can I accomplish this task in PHP: If $last_word also contai ...

What is the best way to utilize php's preg_replace function with a basic string and placeholders?

Suppose I have the text [link="*"] where * can be any value, how can I use php to replace it with <a href="*"> where * represents the same value as before? Would preg_replace be the most suitable method for achieving this task? Thank you in advance ...

Lint error: Unrecognized attribute 'text-fill-color' in CSS (unknown properties)

My navigation bar isn't functioning, and I can't figure out why. It seems like it might be related to this snippet of code: -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; text-fill-color: trans ...

Set the default value for a form control in a select dropdown using Angular

I've been struggling to figure out how to mark an option as selected in my select element, but I haven't had any luck. I've tried multiple solutions from the internet, but none of them seem to be working for me. Does anyone out there have ...

Importing nested JSON arrays into MySQL

I am attempting to insert a JSON array into my MySQL database. Here's the specific structure of the array: ${ "customer_id": "1", "products":[ { "product_id": "1", "product_qty": "2" }, { "product_id": "2", ...

The ezPublish system is indicating that there are insufficient arguments present in the specified function [(''|ezurl()|ne('/'

We are facing the following issues: Any ideas on how to fix this? Error: Not enough arguments at [(''|ezurl()|ne('/'))] This error is occurring in the specific file 'extension/ezcbdigeventcalendar/design/standard/templates/par ...

links contained within a single span inside an anchor tag

I am attempting to place all three spans within an anchor tag, inline. I am not certain what is missing from the code: a.facebook-button { float: none; display: inline-block; margin-bottom: 5px; left: auto; text-shadow: 0 -1px 1px rgba(0, 0, 0 ...

Guide on organizing items into rows with 3 columns through iteration

Click on the provided JSFiddle link to view a dropdown menu that filters items into categories. Each item is stored as an object in an array for its respective category. Currently, all items are displayed in one column and I want to divide them into three ...

Using ajax to call the Google Maps Api is proving to be ineffective

I am facing some issues with a website. On this particular webpage (), I am trying to display a Google map on the location page using an AJAX function. The getLocation.php file is being called by AJAX: <?php echo '<div id="map-canvas"></ ...

Executing a function upon the loading of a template in AngularJS

I have been searching through various responses here, but I haven't come across one that addresses my specific problem. Apologies if this has already been answered. I am a beginner in angular js and have recently begun working on angular routing. I am ...

CSS Grid having trouble with wrapping elements

Greetings to all, As a newcomer to the world of web development, I am currently exploring the wonders of the CSS grid tool. However, I have encountered a roadblock: My intention is for the cards to automatically flow one by one into the next row while ma ...

Issues with Angular HTML failing to load correctly

Greetings, I am seeking assistance with an issue that has been challenging me for quite some time. As a newcomer to Angular JS, I may be overlooking something obvious. Here is the scenario: I am utilizing ng-repeat on a directive in the following manner: ...

CSS Switchable Style Feature

I am in need of some assistance with the navigation on my website. You can find the current code at this link: http://jsfiddle.net/Sharon_J/cf2bm0vs/ Currently, when you click on the 'Plus' sign, the submenus under that category are displayed bu ...

The Ng-include tag does not provide highlighting for its text

Within an ng-include template, I have a div that is not highlighting when hovered over. Although the cursor changes to a pointer when hovering over the text, attempting to click and drag to highlight it results in nothing happening. This issue is signific ...

Bring in styles from the API within Angular

My goal is to retrieve styles from an API and dynamically render components based on those styles. import { Component } from '@angular/core'; import { StyleService } from "./style.service"; import { Style } from "./models/style"; @Component({ ...