What is the best way to position two divs side by side horizontally, each containing an HTML table?

Struggling to align two div elements side by side? One contains a two-column table and the other has a five-column table. Despite using Bootstrap's "row" class, you're unable to get them properly aligned. How can you achieve this layout without any issues? Hopefully, someone can lend a helping hand with this conundrum.

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

Included below is the code snippet:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>trial</title>

    <!--Links for icons and images-->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

    <!--css for paginated-->
    <link rel="stylesheet" href="http://localhost/Performance/css/usermange.css">

    <style>
    #displayproject{
       margin-top:100px;
       position:fixed;
       background-color:blue;
    }
    </style>

</head>

<body>
    <div class="container">
        <div id="displayproject">
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th></th>
                        <th>Projects</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        include_once "../Connection/dbconnect.php";
                        $fetch_projects = mysqli_query($GLOBALS['db'],"select project_id,project_name from project_table limit 10;");
                        while($row = mysqli_fetch_array($fetch_projects)){
                            echo '<tr>
                                <td>
                                    <span class="custom-checkbox">
                                        <input type="checkbox" name="options[]" value="hello">
                                        <label></label>
                                    </span>
                                </td>';
                            echo '<td>'.$row['project_name'].'</td></tr><tr></tr>';
                        }
                    ?>
                </tbody>
            </table>
        </div>
        <div class="table-wrapper">
            <div class="table-title">
                <div class="row">
                    <div class="col-sm-6">
                        <h2>Manage <b>Employees</b></h2>
                    </div>
                    <div class="col-sm-6">
                        <a href="#addEmployeeModal" class="btn btn-success" data-toggle="modal"><i class="material-icons">&#xE147;</i> <span>Add New Employee</span></a>
                        <a href="#deleteEmployeeModal" class="btn btn-danger" data-toggle="modal"><i class="material-icons">&#xE15C;</i> <span>Delete</span></a>                        
                    </div>
                </div>
            </div>
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="selectAll">
                                <label for="selectAll"></label>
                            </span>
                        </th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Address</th>
                        <th>Phone</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="checkbox1" name="options[]" value="1">
                                <label for="checkbox1"></label>
                            </span>
                        </td>
                        <td>Thomas Hardy</td>
                        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c9bda1a6a4a8baa1a8bbadb089a4a8a0a5e7aaa6a4">[email protected]</a></td>
                        <td>89 Chiaroscuro Rd, Portland, USA</td>
                        <td>(171) 555-2222</td>
                        <td>
                            <a href="#editEmployeeModal" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit">&#xE254;</i></a>
                            <a href="#deleteEmployeeModal" class="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete">&#xE872;</i></a>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="checkbox3" name="options[]" value="1">
                                <label for="checkbox3"></label>
                            </span>
                        </td>
                        <td>Maria Anders</td>
                        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5a8a4b7aca4a4aba1a0b7b685a8a4aca9eba6aaa8">[email protected]</a></td>
                        <td>25, rue Lauriston, Paris, France</td>
                        <td>(503) 555-9931</td>
                        <td>
                            <a href="#editEmployeeModal" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit">&#xE254;</i></a>
                            <a href="#deleteEmployeeModal" class="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete">&#xE872;</i></a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

The current output image I'm getting looks like this:

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

Answer №1

To implement bootstrap 3, you can refer to the code provided in this link.

<div class="container">
  <div class="row">
    <div class="col-md-12">
      div is included here 
    </div>
  </div>
  
  <div class="row">
    <div class="col-md-3">
      
      <table class="table table-bordered">
        <thead>
          <tr>
             <th>checkbox</th>
            <th>name</th>
          </tr>
         
        </thead>
        <tbody>
          <tr>

            <td><input type="checkbox" /></td>
            <td>text</td>
          </tr> <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
          </tr> <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
          </tr> <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
          </tr> <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
          </tr>
          
        </tbody>
      </table>
    </div>
    <div class="col-md-9">
       <table class="table table-bordered">
        <thead>
          <tr>
             <th>checkbox</th>
            <th>name</th>
            <th>title</th>
            <th>title</th>
          </tr>
         
        </thead>
        <tbody>
          <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
          </tr>  <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
          </tr>  <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
          </tr>  <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
          </tr>  <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
            <td>text</td>
            <td>text</td> 
          </tr>  <tr>
            
            <td><input type="checkbox" /></td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
          </tr>
          
        </tbody>
      </table>
    </div>
  </div>
</div>

Answer №2

Here is a sample layout that may suit your needs -

<div class="container">
   <div class="row">
     <div class="col-md-12">
        Content in the first div
     </div>
   </div>
   <div class="row">
     <div class="col-md-2 col-sm-2" style="border:1px solid">
        <table class="table">
          <tr>
            <td>col</td>
            <td>col</td>
          </tr>
        </table>
     </div>
     <div class="col-md-10 col-sm-12"  style="border:1px solid">
        <table class="table">
          <tr>
            <td>col</td>
            <td>col</td>
            <td>col</td>
            <td>col</td>
            <td>col</td>
          </tr>
        </table>
     </div>
   </div>
</div>

This code snippet above is just an illustration. You can adjust it as needed.

Fiddle

Answer №3

To make this possible, you need to employ the float:value; attribute that is present in css.

value:left|right|clear

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>customization</title>

    <!--Links for icons and images-->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

    <!--Pagination css-->
    <link rel="stylesheet" href="http://localhost/Performance/css/usermange.css">

    <style>
    #displayproject{
       float:left;
       margin-top:100px;
       position:fixed;
       background-color:blue;
    }
    </style>

</head>

<body>
    <div class="container">
        <div id="displayproject">
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th></th>
                        <th>Projects</th>
                    </tr>
                </thead>
                <tbody>
                   
                </tbody>
            </table>
        </div>
        <div class="table-wrapper" style="float:right;">
            <div class="table-title">
                <div class="row">
                    <div class="col-sm-6">
                        <h2>Manage <b>Employees</b></h2>
                    </div>
                    <div class="col-sm-6">
                        <a href="#addEmployeeModal" class="btn btn-success" data-toggle="modal"><i class="material-icons">&#xE147;</i> <span>Add New Employee</span></a>
                        <a href="#deleteEmployeeModal" class="btn btn-danger" data-toggle="modal"><i class="material-icons">&#xE15C;</i> <span>Delete</span></a>                        
                    </div>
                </div>
            </div>
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="selectAll">
                                <label for="selectAll"></label>
                            </span>
                        </th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Address</th>
                        <th>Phone</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="checkbox1" name="options[]" value="1">
                                <label for="checkbox1"></label>
                            </span>
                        </td>
                        <td>Thomas Hardy</td>
                        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9beff3f4f6fae8f3fae9ffe2dbf6faf2f7b5f8f4f6">[email protected]</a></td>
                        <td>89 Chiaroscuro Rd, Portland, USA</td>
                        <td>(171) 555-2222</td>
                        <td>
                            <a href="#editEmployeeModal" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit"></i></a>
                            <a href="#deleteEmployeeModal" class="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete"></i></a>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class="custom-checkbox">
                                <input type="checkbox" id="checkbox3" name="options[]" value="1">
                                <label for="checkbox3"></label>
                            </span>
                        </td>
                        <td>Maria Anders</td>
                        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="167b77647f77777872736465567b777f7a3875797b">[email protected]</a></td>
                        <td>25, rue Lauriston, Paris, France</td>
                        <td>(503) 555-9931</td>
                        <td>
                            <a href="#editEmployeeModal" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit"></i></a>
                            <a href="#deleteEmployeeModal" class="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete"></i></a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

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

The functionality of aria-expanded="true" is not functioning properly when accessed on mobile devices

I am facing an issue where "aria-expanded="true" does not work when the user closes the dropdown on mobile devices, but it works perfectly fine on desktop browser pages. Desktop <a class="notifLink" data-toggle="dropdown" aria-haspopup="true" id="noti ...

How can I modify the appearance of sibling elements when I hover over one?

Here is a code snippet: <div class="main"> <a href="" target="_blank"> a </a> <a href="" target="_blank"> b </a> <a href="" target="_blank"> c </a> <a hr ...

The alignment of Bootstrap 4 cards is not coming together as expected

Good morning, I'm currently working on organizing my Bootstrap card elements into rows of 3 cards each. I want the cards to be uniform in height and width, with spacing between them. For instance, if I have 7 cards, I'd have 3 rows of three card ...

Is it Possible for TD Not to Function as a Hyperlink?

I've exhausted all topics but nothing seems to be working for me! My goal is to have a table completely covered with anchor tags, but for some reason, it's not displaying any links within the TD elements, not even the text! HTML <tab ...

Avoiding the appearance of a scrollbar when content extends beyond its containing block

I am struggling with writing markup and CSS to prevent a background image from creating a scrollbar unless the viewport is narrower than the inner content wrapper: The solution provided in this post didn't work for me: Absolutely positioned div on ri ...

Incorporating a transparent icon onto an HTML background

I'm struggling to place a transparent white envelope icon on a green background. I don't understand why it's not working, especially when the telephone icon worked fine. Side Question.: Any recommendations for how to add something above the ...

How can I implement a hover effect without triggering a click event?

My structure is pretty basic, here it is: .container { height: 100vh; width: 100%; pointer-events: none; } .click-layer { background-color: #ccc; position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: auto; } .box { ...

How can I trigger a function once ng-show has finished executing?

I have an HTML table and buttons with the attribute ng-show=some_property. What I am trying to achieve is: I want Button1 to reveal a table containing field1, and I would like to change the focus directly from Button1 to field1. However, I am encounterin ...

Alter the style attribute using JavaScript

I have a calendar table row that needs to be displayed or hidden based on the month. HTML: <tr id="bottomrow" class="week" valign="top" style="display:none;"> <td class="day" id="d36"> <div class="daynumb" id="x36">& ...

Using HTML video to fill entire div container

I'm currently facing an issue with using an HTML video as a fullscreen background replacement for an image. The problem is that the video overflows and covers the entire page instead of staying within the constraints of the header section. Here is th ...

Avoid losing focus on href="#" (preventing the page from scrolling back up to the top)

Is there a way to prevent an empty href link from causing the page to scroll up when clicked? For example, if I have: <a href="#">Hello world</a> And this "Hello world" link is in the middle of the page. When clicked, the URL would look like ...

JS-generated elements do not automatically wrap to the next line

For my first project, I've been working on a to-do list and encountered an issue. When I create a new div with user input, I expect it to start on a new line but it remains stuck on the same line. Can anyone point out where I might have gone wrong? I ...

hide the scroll button when at the top of the page and hide it when at the bottom

Looking to create a vertical scroll that hides the up button when at the top and hides the down button when at the bottom? Jquery can help with this, but sometimes it's tricky to get it just right. Take a look at an example here. Below is the code sn ...

Prevent the float:left property from causing my div to overlap with another div

Is there a way to style "a" so that it can take up space and float to the left simultaneously? <div style="background:#111"> <div id="a" style="float:left; height:30px"></div> </div> ...

Angular 13 doesn't recognize ViewChild

I am encountering an issue where I am attempting to access the view child of a child component from the parent component, but I keep getting an 'undefined' error in the console. Please refer to the image and check out the stack blitz for more de ...

Align the radio buttons vertically

My goal is to align all my buttons vertically, similar to the first question. However, I'm struggling to get the second question to align correctly. Despite trying different methods like using the vertical-align: middle property, nothing seems to be w ...

Deliver JavaScript and HTML through an HTTP response using Node.js

My attempts to send both a JavaScript file and an HTML file as responses seem to be failing, as the client is not receiving either. What could be causing the client to not receive the HTML and JavaScript files? I am using Nodejs along with JavaScript and H ...

How can I align text to the right in a navbar using Bootstrap 5?

My current navbar setup is as follows: <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container-fluid"> <div class="collapse navbar-collapse" id="navbarText"> ...

The MediaStream Recording API is failing to capture video from the canvas element

I have been attempting to record and download video from a canvas element using the official MediaStream Recording API <!DOCTYPE html> <html> <body> <h1>Testing mediaRecorder</h1> <canvas id="myCanvas" w ...

A step-by-step guide on showcasing three post images in separate divs at the bottom of a webpage with Reactjs and Css

In the array below, there are three post photos. When I click on each post button, I should see a corresponding post photo div at the bottom for each post. Issue: I am facing a problem where only one post photo div is being displayed, which keeps replaci ...