responsive table design with Bootstrap 4

Hi there, I'm encountering an issue while attempting to utilize the responsive table feature in Bootstrap 4.

If the table doesn't have enough content to fill the complete width, it ends up looking like this:

Table Layout https://i.sstatic.net/JLSMB.png

Here is a snippet of my code:

<div class="container" id="maincontainer">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<p>Upcoming Events:</p>
    <table class="table table-responsive table-hover">
    <thead>
      <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
      </tr>
    </thead>
    <tbody>
   </tbody>
</table>

<p>Past Events:</p>
    <table class="table table-responsive table-hover">
    <thead>
      <tr>
        <th>#</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
      </tr>
    </thead>
    <tbody>
    <tr>
      <th scope="row">30.06.2017 15:30 - 16:00</th>
      <td>2/2</td>
      <td>dafdfsfa</td>
      <td>97</td>
    </tr>
</tbody>
</table>
</div>

I would greatly appreciate any assistance with resolving this matter.

Warm regards, Alex

Answer №1

The reason for the discrepancy is that you are dealing with two distinct tables containing varying lengths of text in their first columns. To achieve uniformity in column width, one possible solution would be to ensure both tables have an equal number of characters by incorporating a date and time stamp into the first table.

Answer №2

In JavaScript, you have the option to define a specific width as shown below:

$('.table').dataTable( {
  "columnDefs": [
    { "width": "30%" },
    { "width": "20%" },
    { "width": "20%" },
    { "width": "30%" },
  ]
} )

Answer №3

When working with a bootstrap table, the width of each column will adjust based on the data within.

If you want all columns in your table to be the same width, consider using a <div> instead of a traditional Table.

<p>Upcoming Events:</p>
<div class="row">
    <div class="col-md-3">
       <b>#</b> 
    </div>
    <div class="col-md-3">
      <b> First Name</b> 
    </div>
    <div class="col-md-3">
      <b>  Last Name</b>
    </div>
    <div class="col-md-3">
       <b>Username</b> 
    </div>
</div>
<br />
<p>Upcoming Events:</p>
<div class="row">
   <div class="col-md-3">
     <b>#</b>
   </div>
   <div class="col-md-3">
     <b> First Name</b>
   </div>
   <div class="col-md-3">
     <b>  Last Name</b>
   </div>
 <div class="col-md-3">
    <b>Username</b>
  </div>
</div>

<div class="row primary-bordered-table">
  <div class="col-md-3">
      30.06.2017 15:30 - 16:00
  </div>
  <div class="col-md-3">
      2/2
  </div>
  <div class="col-md-3">
      dafdfsfa
  </div>
  <div class="col-md-3">
      97
  </div>
</div>

Your layout will resemble the image found here:

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

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

When I scroll down, the <div> below the <header> disappears, but only the header should be invisible. Can anyone explain why this is happening?

Check out this JsFiddle link for reference. I have implemented the Material Design Lite framework in my project. In the header section, I want to include a Title row, a row that displays a description (labeled as Story followed by some text), and a row fo ...

Tips for effectively managing index positions within a dual ngFor loop in Angular

I'm working on a feedback form that includes multiple questions with the same set of multiple choice answers. Here's how I've set it up: options: string[] = ['Excellent', 'Fair', 'Good', 'Poor']; q ...

Tweaking the placement of the dropdown menu in the subnavigation area

Just getting back into coding after a long hiatus - I've dabbled in the past but it's been about 6 years since I've worked with any code. Currently, I'm working on replicating a website for practice. I have created a nav bar and a drop ...

Optimizing Title Tags for Static Pages with Header Inclusion

Working on developing static web pages for a client who preferred not to use a content management system. These pages all have a shared header and footer php files. I am in need of creating unique title and meta description tags for each page, but I am un ...

Clickability issue with RSelenium radio button

Currently, I am utilizing RSelenium for web scraping tasks on a particular website. Unfortunately, I have encountered an issue when attempting to select a radio button. Here is the HTML snippet: <div class="radio"> <input type="radio" name="se ...

Effortlessly lower several elements simultaneously with SlideDown

My form div contains multiple inner divs: <div class="form" style="display:none"> For example: <div class="row"> <?php echo $form->labelEx($model,'comment'); ?> <?php echo $form->textField($model,'commen ...

The function `$('body').on('blur')` is having issues in Internet Explorer 8

How can I fire a function when $('body').on('blur') occurs? This code works perfectly in all browsers except for IE8 $(document).ready(function () { $(window).focus(); $(window).on("focus", function () { ...

What HTML element can be used outside of a Bootstrap dropdown item to show a default image when the dropdown is open?

I'm working on my menu where I have two columns - one for submenu text and the other for respective images. Everything is working fine so far. However, I want to set a default image that will display when the user does not hover over any dropdown item ...

Displaying a single row of a PHP array in bold formatting

I have a MySQL query result showing user information and subjects they have chosen. I want to highlight one specific row by making it bold using PHP while keeping the rest as regular text. How can I achieve this? $resultSet = $db->query ("...my q ...

Utilizing AngularJS to display numerous charts on a single webpage

Currently, I am looking for a solution to display multiple charts on the same page. My goal is to showcase individual performance through each chart for different persons. After exploring Google Charts, I noticed that it requires unique "id" attributes w ...

What is the technique for rearranging columns to be at the top in Foundation for mobile devices?

On my desktop, I have a layout like this: [Column1 large-8] [Column2 large-4] For mobile view, I'd like it to be like this: [Column2 large-4] [Column1 large-8] Below is the code snippet I am working with: <div id="search-content" class="row ma ...

What are some creative ways to enhance the functionality of a single button?

I'm looking to create a custom radio player, but I'm struggling with implementing the functionality where the button toggles between "PLAY" and "PAUSE". Here is the code I have so far: function play() { var audio = document.getElementById("a ...

Execute a JavaScript function on a Node server following a click event in an HTML document

Hello everyone, I am currently working on a project using node.js in a Windows environment. With the help of the express module, I am trying to create a static page that includes a Submit form. When someone clicks the "Submit" button, I intend to execute a ...

Unable to transfer a value from a CGI script back to an HTML form

When working with an HTML form that has a date field named cdt, I encountered the need to retain the date value when submitting data to an Oracle table through a CGI script. To achieve this, instead of using Javascript code like history.go(-1), I aimed to ...

What is the best way to implement a table using JavaScript?

I am struggling to add a table to my HTML document dynamically using JavaScript. Despite trying various methods like appendChild and insertBefore, I have not been successful. Below is the snippet of my JavaScript code: //JavaScript code here... Here is ...

The image does not automatically adjust size when the window is resized

I'm having an issue with my HTML and CSS code that is supposed to display two images side by side and resize when the browser window shrinks, but it's not working as expected. Even after removing all classes on the parent divs, the images still ...

Importing JSON data from a URL to display in an HTML table

Looking to utilize the Untappd API for a beer menu project, I've encountered an issue. The goal is to showcase the JSON data received from the server and organize it into an HTML table. Despite successfully importing data from a local list.json file ...

Display a helpful tooltip when hovering over elements with the use of d3-tip.js

Is it possible to display a tooltip when hovering over existing SVG elements? In this example, the elements are created during data binding. However, in my case, the circles already exist in the DOM and I need to select them right after selectedElms.enter ...

Understanding the fundamentals of event handling in JavaScript

Is there a way to access the object that called the event handler within the event handler function itself? For example: marker.on('dragend', onDragEnd); In this case, marker is the object that triggers the ondragEnd function on the Dragend eve ...

The html button adorned with a variety of CSS styles

I've been attempting to create a button for a message system that displays an orange dot when there's a new message, but I'm having trouble getting it to work. Do you think it's possible? Check out the button below: <input type="bu ...