Two tables arranged in a nested grid layout

Picture a bootstrap grid setup with an 8:4 layout.

<div class="container">
    <div class="row">
        <div class="col-md-8">
        </div>
        <div class="col-md-4">
        </div>
    </div>
</div>

The user has the ability to adjust the content within this grid. They can choose to place their content in either of the columns, depending on their needs.

For example, consider two tables:

<div class="row">
    <div>
        <table>
        </table>
    </div>
    <div>
        <table>
        </table>
    </div>
</div>

If the two tables are placed in the larger column, they should sit side by side until a certain screen width is met, at which point they should stack on top of each other.

Conversely, if the two tables are placed in the smaller column, they should always appear stacked on top of each other due to the limited space available.

Is it possible to achieve this using just CSS?

Furthermore, as the layout becomes even smaller, both columns should eventually stack on top of each other. With the "col-md-" classes used, reaching the specified breakpoint should trigger this stacking behavior. However, if the user places two tables in the smaller column and the "md" breakpoint is reached, there may be some minor discrepancies in the layout. Is it possible to avoid these discrepancies, or will they have to be accepted as part of the design?

Answer №1

Absolutely, achieving this nesting is a breeze with just the native Bootstrap 4 classes on their own.

All you have to do is place row-column pairs within a column of your choice as demonstrated below:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container">
    <div class="row">
        <div class="col-md-8 mb-3">
            <p>wide column</p>
            <div class="row">
                <div class="col-md-6">table 1 goes here</div>
                <div class="col-md-6">table 2 goes here</div>
            </div>
        </div>
        <div class="col-md-4">
            <p>narrow column</p>
            <div class="row">
                <div class="col-sm-6 col-md-12 col-lg-6">table 3 goes here</div>
                <div class="col-sm-6 col-md-12 col-lg-6">table 4 goes here</div>
            </div>
        </div>
    </div>
</div>

This snippet will achieve the exact layout behavior you outlined. When the screen size is smaller than md, the elements will stack vertically. On larger screens, the tables will be positioned side by side, each occupying 50% of the available space in their respective parent columns.

If you find that even at the sm breakpoint there's sufficient room for two tables to be displayed beside each other, you can modify the classes of the inner columns to something like col-sm-6. This adjustment would ensure they are positioned horizontally at that breakpoint.

Remember, it's crucial to always maintain row-column pairings when nesting elements, or else the layout may encounter issues.

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

Swapping icons in a foreach loop with Bootstrap 4: What's the most effective approach?

I need a way to switch the icons fa fa-plus with fa fa-minus individually while using collapse in my code, without having all of the icons toggle at once within a foreach loop. Check out a demonstration of my code below: <link rel="stylesheet" href= ...

Ways to have a list component smoothly descend when a dropdown menu is activated

I have a situation where I have a list with two buttons, and each button triggers the same dropdown content in a sidebar component. The issue is that when I click on one button to open the dropdown, the second button does not move down to make space for it ...

Creating button groups with a centered .btn using Bootstrap 4

My button group has a link in the middle, so it needs to be an a tag. I could change it to a button and use JavaScript for navigation, but I'd prefer not to. Here is the code: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bo ...

Tips for aligning content produced by *ngFor within a bootstrap grid

I am trying to center content in a row using the Bootstrap grid system. While I have checked out various examples, such as this one, my case is unique because I am utilizing a separate angular component for generating the content. Here is the code snippet ...

Ways to navigate to a different page using HTML response from an AJAX request

After receiving an HTML document as a response from an AJAX call, I need to create a redirection page using this HTML response. Can anyone provide guidance on how to achieve this? ...

Execute function upon changing the title of a list item using jQuery

Hey there, I've got a question for you. Is it possible to trigger an event when the title of a list element is changed? For example: <ul> <li id="li_1" title="40">40</li> </ul> So when the title attribute changes (coming ...

Serializing Form Data with Checkbox Array

I am currently utilizing JQuery to submit a form using the form.serialize method. However, within the same form, there is an array of checkboxes that are dynamically created by a PHP function. Here is the structure of the form: <form class="form" id="f ...

The controller and node js request associated are invisible to my HTML page

Here is my HTML code. I have just created a unique controller for a specific part of the code. <div class="mdl-grid" ng-controller="ValueController"> <div class="mdl-card mdl-shadow--4dp mdl-cell--12-col"> <div class ...

The background image and svgs are not displayed on laravel localhost/public/index.php, but they appear when using "php artisan serve"

I've created a beautiful Laravel project on my PC. The welcome.blade.php file in the project has a background image located in the: public/images/ directory. To display the images, I've used the following CSS: html, body { color: #f4f6f7; ...

What is the most effective way to assign multiple functions to the onClick event of a button, based on a specific property,

I have a special button that generates a specific type of code when rendered: <button>{this.props.text}</button> This button is named ButtonCustom. In the render method of the main container, I am trying to achieve the following: function my ...

When resizing the browser or changing resolution, one div may cover another div

After generating the HTML on my ASP.NET page, everything looks good initially. However, I noticed that when I adjust the screen resolution or reduce the browser size, the image in the logoplace div starts to overlap. It appears to be an issue with absolute ...

Ways to incorporate smooth transitions to content using CSS

I recently created a website for a competition and I am looking to make the text change when a user hovers over a link. While I have managed to achieve the text change, I now want to add a transition to it. I have only used CSS to change the code. Can some ...

What is the best approach to decrease the size of a button in HTML and CSS when the text size is also reduced?

Check out this code snippet! I'm new to coding, so let me know if you see any errors or ways it could be improved. button { font-size: 10px; font-family: roboto, Arial; color: white; background-color: rgb(59, 102, 241); border-radius: 100p ...

Switch up the font style of the title element

Is it possible to modify the font-family of the title attribute in an input field using either JavaScript or jQuery? <input type="text" title="Enter Your Name" id="txtName" /> ...

JQuery hover effect causes mouse pointer to flicker

I'm currently working on creating a mega menu using Bootstrap 4, and I came across this code: While the code works well, I wanted to add a slide down/slide up effect to reveal the dropdown content when hovering over the dropdown link. So, I included ...

Customizing a ControlsFX PopOver in a JavaFX application

I am looking to personalize the appearance of a JavaFX PopOver control. I have a button that triggers the display of the PopOver. Below is a functional example: package custompopover; import javafx.application.Application; import javafx.event.ActionEvent ...

Strange Behavior of Json Dataset

I've noticed some unusual behavior when loading JSON data via AJAX with an interval. Initially, the data loads correctly, but after a few intervals, it starts to get scrambled and runs unpredictably between intervals. This issue even leads to crashes ...

Learn how to showcase video information in a vue.js template

I am having difficulty displaying a saved media (video) file on another page after collecting it using the ckeditor5 media option. The data is stored along with HTML tags generated by ckeditor, so I'm using v-html to display other content like <p&g ...

PyQt TreeView scrollbar obstructing the header

I've been experimenting with the QTreeView widget (instead of QListView) in order to have a horizontal header. Additionally, I wanted to use stylesheets to customize the colors and appearance of the header and scrollbars. However, there is an issue w ...

Laravel 8 - sweet alert functions properly, however, the ajax functionality is not functioning as expected

As a newcomer to Ajax, I am facing an issue with deleting records from the database using Sweet Alert2. Although my swal is working fine, the ajax function seems to be malfunctioning. Can anyone point out where the problem might be and suggest a solution? ...