Position a div next to a table and include scrollbars

My challenge is to create a responsive layout with a table and a side div, as shown in the image below. I attempted to use CSS float properties for the table and side div, but it did not provide the responsiveness I needed. I then tried implementing Bootstrap's grid system, but encountered difficulties. Additionally, I require scrollbars for both the table and side div.

You can find my code on StackBlitz.

.test{
    overflow-y: auto !important; 
    height: 100% !important;
}
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
  <div class="ml-auto">
    <input
      class="form-control"
      name="search"
      [(ngModel)]="search"
      type="search"
      placeholder="Search"
    />
  </div>
</nav>
<br /><br />
<section>
  <div class="w-75 float-left overflow-auto test">
    <table class="table table-hover">
      <tr>
        <th>Date</th>
        <th>List Name</th>
        <th>No. of Entities</th>
    
      </tr>
      <tbody>
        <tr *ngFor="let items of data | filter: search">
          <td>{{ items.date }}</td>
          <td>{{ items.name }}</td>
          <td>{{ items.entities }}</td>
          <td>
            <button type="button" class="btn btn-outline-secondary" (click)="getdetails(items)">
                Details
              </button>
          </td>

          
        </tr>
      </tbody>
    </table>
  </div>
</section>
<br />
<aside>
  <div class="w-20 float-right overflow-auto test">
    <div class="alert alert-dark">+Add Description</div>
    <p>{{s}}</p>
  </div>
</aside>

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

Answer №1

Here is how I tackled the problem using bootstrap for a responsive design.

I enclosed your content within the .container-fluid class and then organized the inner elements with .row and col-* classes. Check out the example in full view.

To ensure 100% height, I employed height: calc(100vh - 54px);

The usage of 100vh makes it take up the entire viewport height.

The subtraction of 54px was necessary to prevent the need for scrolling through the whole page.

.test {
  overflow-y: auto !important;
  height: calc(100vh - 54px);
  /*54px accounts for navbar height*/
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
  <div class="ml-auto">
    <input class="form-control" name="search" [(ngModel)]="search" type="search" placeholder="Search" />
  </div>
</nav>
<br/><br/>
<div class="container-fluid">
  <section class="row">
    <div class="col-md-8 col-12 overflow-auto test">
      <table class="table table-hover">
        <tr>
          <th>Date</th>
          <th>List Name</th>
          <th>No. of Entities</th>

        </tr>
        <tbody>
         <!--repeated data display component-->
        </tbody>
      </table>
    </div>
    <div class="col-md-4 col-12 overflow-auto test">
      <div class="alert alert-dark">+Add Description</div>
     <!--repeated sample data displayed -->
      
    </div>
  </section>
</div>

Answer №2

Utilizing bootstrap makes creating responsive layouts a breeze. The framework is specifically designed for this purpose.

To align two divs next to each other on larger screens and stack them on top of each other on smaller screens, you can utilize the col-{size}-{n} CSS classes within a .container > .row structure. Here, size can be xs, sm, md, lg, xl, with n ranging from 1 to 12.

For instance, let's say we use col-md-8 and col-md-4 in your example. By setting the breakpoint to -md-, when the screen size is greater than or equal to 768px, the divs will be side by side. Conversely, they will stack on top of one another if the screen size is less than 768px.

Check out this demo for reference

<div class="container">
  <div class="row">
    <div class="col-md-8">
      <!-- Place your table content here -->
    </div>
    <div>
      <!-- Add your aside content here -->
    </div>
  </div>
</div>

If you want to explore more options and features offered by Bootstrap, refer to their comprehensive documentation: Bootstrap Layout Grid

Answer №3

Instead of relying on w-75, consider utilizing the Bootstrap Grid System. Simply wrap your code within the

.container > .row > .col-*-*
structure for a more organized layout. I hope this tip proves helpful!

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<section>
  <div class="container">
    <div class="row">
      <div class="col-md-8">
        <table class="table table-hover">
          <tr>
            <th>Date</th>
            <th>List Name</th>
            <th>No. of Entities</th>

          </tr>
          <tbody>
            <tr *ngFor="let items of data | filter: search">
              <td>{{ items.date }}</td>
              <td>{{ items.name }}</td>
              <td>{{ items.entities }}</td>
              <td>
                <button type="button" class="btn btn-outline-secondary" (click)="getdetails(items)">
                  Details
                </button>
              </td>


            </tr>
          </tbody> 
        </table>
      </div>
      <div class="col-md-4">
        <div class="alert alert-dark">+Add Description</div>
        <p>{{s}}</p> 
      </div>
    </div>
  </div>
</section>
</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

What is the best way to eliminate padding for a specific element within a div container?

In my bootstrap design, I have nested columns where the grey background color for my h3 element has gaps on the left and right due to the padding of the bootstrap columns. While I can remove the padding by using padding:0px, this will affect all elements ...

Strategies for managing grid overflow situations

Check out my codepen showcasing the current issue I'm dealing with: https://codepen.io/marcdaframe/pen/qeBWNd <div> 123 abc <div class="container"> <div class="wrapper"> <div>One</div> <div>Two</div> ...

The sequencing of code execution in JavaScript (illustrated using an example in d3-force)

I'm currently delving into this code to grasp the inner workings of d3-force. As I examine the variable nodes, I am intrigued by how positions are assigned to them. // Replace the input nodes and links with mutable objects for the simulation. con ...

Uploading images in PHP

I need assistance with uploading an image to a server using PHP, saving it inside a directory, and then retrieving the image URL. Here is my HTML code: <form method="post> <fieldset> <div class="form-group col-md-6 col-lg-6 col-sm-1 ...

How can I show the initial three digits and last three digits when using ngFor loop in Angular?

Greetings! I have a list of numbers as shown below: array = [1,2,3,4,5,6,7,8,9,10] By using *ngFor, I am displaying the numbers like this: <div *ngFor =" let data of array"> <p>{{data}}</p> </div> Now, instead of d ...

Modify html to style certain words without the need for tags

Can words be automatically styled? I am looking to create a code where specific words like "fire" and "ice" change to red and blue respectively without the need for additional tags like span or p. Is this achievable? ...

retrieve the tooltip from a button with selenium

Just starting out with Selenium and feeling a bit lost. I'm trying to figure out how to capture the tooltip from this HTML code snippet: <a id="aui_3_4_0_1_2236" title="Graceful shut down of the platform and power-off the hardware."> <sp ...

Error message indicates failure of switch case, resulting in invalid output of

My BMI calculator was working fine until I switched the conditionals to a switch statement for cleaner code. Now, the code is breaking and the result variable isn't being set properly for display. Do you have any ideas on what could be missing here? ...

Developing Functions using MongoDB Console

When running the query db.graduates.find({student_id: '2010-01016'}).pretty(), it returns a result. Afterwards, I created a function: function findStud(name,value){ return db.graduates.find({name:value}); } However, while executing findStud("s ...

Tips for choosing additional rows from an HTML table

I am using jQuery to create a hover effect on table cells: $('td').hover(function () { var t = $(this), index = t.index(); // the position of the TD in the row, so you can find the one below it t.addClass('hovered'); // a ...

How to stop the mobile keyboard from hiding in JavaScript

On a webpage, I have an HTML setup with an editor and buttons positioned above the keyboard: ------------ |1| Hello | |2| World | | | | | | | ------------ |Tab|( ) [ | ------------ |qwertyuiop| | asdfghkl | | zxcvbnm | | [ ] | ------- ...

What is the best way to include a character in a string if there are no instances of the same character already present?

Looking for help with a function that can determine if a string contains a period and add one if it doesn't. So far, I'm struggling to make it either continuously add periods or not add any at all. function checkPeriod() { if (inputString.indexO ...

Issue with Vue.js - Double curly braces not rendering data on the page

I've recently delved into the world of vue.js Strangely enough, the double curly braces syntax doesn't seem to be rendering for me. However, when I utilize the v-text directive, everything falls into place. Here's a snippet of my code: HTM ...

Error message keep showing up with "TypeError: document.getElementById(...) is null"

While trying to solve the exercise on creating a budget calculator, I encountered some errors in my code that were not present in the professor's solution. Even though I filled out all the necessary tables, I kept getting errors when attempting to upd ...

Troubleshooting: The Google Analytics Universal Event Tracking Code is not functioning as

I am having trouble tracking clicks on an image that links to another site in a HTML widget on my website’s sidebar. I have implemented Google Analytics code, but for some reason, the clicks are not showing up in the "Events" tab of my analytics dashboar ...

Creating a stylish CSS shadow effect for a collection of elements

In my Ionic2 project, I have an <ion-list> consisting of various items. Currently, these items are plain, but I desire to add some styling such that each item in the list displays a subtle shadow effect, similar to the one shown in the first image of ...

Exploring Relative Rotations in Three.js

I currently have a scenario where I have a THREE.Scene containing two meshes, namely meshA and meshB. Both of these meshes have been rotated differently. My objective is to take meshB out of the scene and attach it as a child of meshA, while maintaining it ...

Automatically scrolling down with Vue3 and Ionic: A seamless scrolling experience

In the process of developing a VueJS App with Ionic, there is a Chat feature involved. It is crucial for users to view the latest message first and not the oldest one, so it is necessary for the app to open with the container scrolled to the bottom. Additi ...

Ways to select the initial 10 rows, final 3 rows, and middle 2 rows using Javascript

As a newcomer to Javascript, I have a couple of questions: 1) How can I retrieve the first 10 rows, the last 3 rows, and the 2 rows in the center using the code var firstTable = $('#aaa table').eq(0); 2) Is there a way to create and assign new ...

Encountering a 500 error while attempting to pass HTML via an AJAX call to a C# MVC Controller

Currently facing a challenge that I need help with. I have multiple pages successfully making Ajax calls to my C# controllers, but now I'm trying to incorporate a simple content management feature. The goal is to update HTML stored in a database with ...