When the width of a single table is large, Bootstrap tables can appear misaligned and not properly

I am facing an issue with displaying two tables side by side. Whenever the width of the first table is too large, the second table is pushed below it. https://i.sstatic.net/w8zwp.png

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

Is there a way to make them stay side by side and only shift below each other when the screen width is insufficient?

Here is the code I am currently using:

<div class="container">
<div class="row">
    <div class="col-sm">
    <h3>Students</h3>
    <div class="row">
        <a href="/newstudent" class="button-sm">New</a>
    </div>
    <table>
        <tr>
            <td>Username</td>
            <td>First name</td>
            <td>Surname</td>
        </tr>

        <tr>
            <td><a href="/editstudent/lilyliam">lilyliam</a></td>
            <td>Lily</td>
            <td>Liam</td>
        </tr>

        <tr>
            <td><a href="/editstudent/gracenoah">gracenoah</a></td>
            <td>Grace</td>
            <td>Noah</td>
        </tr>

        <tr>
            <td><a href="/editstudent/avawilliam">avawilliam</a></td>
            <td>Ava</td>
            <td>William</td>
        </tr>

        <tr>
            <td><a href="/editstudent/avawilliam">avawilliam</a></td>
            <td>Ava</td>
            <td>Williamsssssssssssssssssss</td>
        </tr>

    </table>
    </div>
    <div class="col-sm">
    <h3>Teachers</h3>
    <div class="row">
        <a href="/newteacher" class="button-sm">New</a>
    </div>
    <table>
        <tr>
            <td>Username</td>
            <td>First name</td>
            <td>Surname</td>
            <td>Type</td>
        </tr>

        <tr>
            <td><a href="/editteacher/johnsmith">johnsmith</a></td>
            <td>John</td>
            <td>Smith</td>
            <td>ADMIN</td>
        </tr>

        <tr>
            <td><a href="/editteacher/williamjoseph">williamjoseph</a></td>
            <td>William</td>
            <td>Joseph</td>
            <td>teacher</td>
        </tr>

        <tr>
            <td><a href="/editteacher/franksmith">franksmith</a></td>
            <td>Frank</td>
            <td>Smith</td>
            <td>teacher</td>
        </tr>

    </table>
    </div>
</div>
</div>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}

th, td {
    padding: 5px;
}

th {
    text-align: left;
}

I am currently using bootstrap for all other CSS styles. Thank you!

Answer №1

If you are utilizing the official bundle of Bootstrap's CSS, you can align tables side by side by following this approach:

<div class="container">
  <div class="row">
    <div class="col-md-6">
      <h1>Table 1</h1>
      // Insert Table 1 Here
    </div>
    <div class="col-md-6">
      <h1>Table 2</h1>
      // Insert Table 2 Here
    </div>
  </div>
</div>

Give this code a try and see if it meets your requirements.

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

What is the best way to rotate a cube when it is clicked on?

My current project involves rotating a cube by clicking on buttons either on the cube itself or floating next to it. At the moment, I have them floating for easier testing purposes, but placing them directly on the cube is not an issue. The main issue I&a ...

Trigger an event in jQuery when the focus moves away from a set of controls

Within a div, I have three textboxes and am looking for a way to trigger an event when focus leaves one of these inputs without transitioning to another one of the three. If the user is editing any of the three controls, the event should not be triggered. ...

Angular 8 is facing an issue where classes defined dynamically in the 'host' property of a directive are not being properly applied to the parent template

In my Angular 8 application, I am working on implementing sorting using the ng-bootstrap table. I referred to the example available at . In the sample, when I hover over the table header, it changes to a hand pointer with a highlighted class applied as sho ...

Tips for showcasing multiple tables based on certain criteria

Hey there, I'm currently working on an inventory page where I want to display multiple tables based on department values. The goal is to have each department in its own table instead of all merged into one. It would definitely make the page easier to ...

How can I ensure that my HTML form inputs are consistently displayed in the browser when using jQuery/AJAX and SQL queries without needing to

My goal is to show all textarea inputs in the browser even after a page refresh, as currently when I send data from homepage.php using jQuery/AJAX, it disappears upon refresh. The information is sent from homepage.php to data.php via the #textarea input an ...

Exploring the potential of utilizing the "wait" function in Selenium WebDriver for

I want to automate a test on my website using the Selenium WebDriver for JavaScript. How can I approach running tests here with content that may not be ready when the page loads, such as data coming from an external API? In my case, the content is loaded ...

Combining two table headers into one table and organizing it for a clean appearance

Is it possible to use two different <thead>'s in the same table but have them stacked neatly? Currently, the first heading has 1 fewer column than the second one, resulting in a slightly awkward appearance. If there is a way to extend that first ...

Deactivate the Submit button when the database field has been populated

My form includes a submit button. The Submit button should be disabled if the "price" for a specific product is already filled: PHP Code <?php $host="localhost"; $username="root"; $password=""; $db_name="ge"; $con=mysqli_connect("$h ...

Responsive columns and fluid Flex row implemented in Bootstrap 4

I am striving to optimize this section for responsiveness. It looks fantastic on larger viewports, but as we start shrinking down, for instance, on a viewport around 930px, I'm facing difficulty in keeping the image perfectly aligned as shown in the i ...

The previous method of using `vue/compiler-sfc ::v-deep` as a combinator has been phased out. Instead, opt for the new syntax `:deep(<

When developing with Nuxt 2, I am encountering numerous [@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead. errors when running npm run dev. After attempting to resolve the issue by changing a ...

When the mouse is clicked, the character fails to reach the intended destination or moves in the wrong direction on the HTML canvas

UPDATE: RESOLVED I am currently working on a game where the character moves by right-clicking. The character is meant to walk slowly, not teleport, towards the destination set by right-clicking on the canvas. However, I have encountered an issue where the ...

PHP regular expression that identifies a specific HTML element

Similar Question: Effective ways to parse HTML using PHP I am currently creating a custom WordPress template for a client that requires a PHP function to extract specific HTML tags as defined by the function. For instance, if I input "div" into the f ...

sticky header on pinned tables in a React data grid

I have combined 3 tables together, with the middle table containing a minimum of 15 columns. This setup allows users to horizontally scroll through the additional columns conveniently. However, I am facing a challenge in implementing a sticky header featu ...

Conceal the toolbar element if it is not at the top of the page

I am encountering an issue with my toolbar. When I scroll down, the transparent background of the toolbar disappears and it looks like this: https://i.sstatic.net/YxZQe.png. How can I hide this component when the page is scrolled down and show it again whe ...

Exploring the Relative Positioning of Two div Elements

Can anyone assist me with finding and comparing the positions of two '<div>' tags using an if statement? I stumbled upon a suggestion in my research, which goes like this: var obstacle = $('#obstacle').css('left', &apo ...

How to eliminate arrow icons from Bootstrap Carousel

Welcome to my blog at www.lowcoupling.com. I am trying to hide the left and right arrows on the bootstrap carousel, but my code doesn't seem to be working. Here is what I have tried: .glyphicon-chevron-right{ display:none; } (I also tried the ...

Is my Bootstrap malfunctioning? The grid system seems to be malfunctioning

My very first question here is quite simple. I have a script that creates rows with dynamic content by appending 4 boxes (columns) in one row and then appending the row to the container. After completing this process, it appends the container to the main c ...

How can I effectively access and view HTML files within VSCode while utilizing WSL?

Has anyone else experienced issues with the open-in-browser extension? Whenever I try to open my HTML file for a project, it doesn't load in the browser. I've attempted storing my repository in different directories on Linux and even in a folder ...

When will the search bar toggle and the logo appear sliding down?

.navbar { background-color: #F91F46; } .src-bar { border: 0; border-radius: 5px; outline: none; padding-left: 15px; width: 30vw; } <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" in ...

Developing a custom mixin to alert a banner at the top of the webpage

I currently have a feature on my website that triggers a pop-up notification whenever a message is received from another user. The pop-up consists of a div displaying the content of the message along with a close button. After exploring various methods to ...