Achieving Full Row Height in Twitter Bootstrap using CSS Grid

Before jumping to conclusions and marking this question as a duplicate, I want to clarify that I have already explored all suggestions provided on Stack Overflow, including the use of display: table. Unfortunately, none of them seem to work smoothly with Bootstrap.

My goal is to achieve a layout structure as depicted below:

---------------------
|      Nav Bar      |
|-------------------|
|      |Body |      |
|      |     |      |
|______|_____|______|
|      |     |      |
|      |     |      |
|______|_____|______|   

The navbar should remain fixed at the top. The body section below should be divided into 6 sub-divs, each occupying 4 columns in width.

The height of the body section needs to adapt dynamically based on the remaining space after accommodating the navbar, which may vary upon resizing.

To ensure maximum browser compatibility, I am looking for a CSS-only solution and steering clear of the flexbox approach.

Below is the snippet of code I am currently using:

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

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

    <!-- Bootstrap CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

    <!-- Custom Styles -->
    <style>
        html,
        body {
            height: 100%;
            padding: 0px;
            margin: 0px;
        }

        .first_wrapper {
            padding: 0px;
            margin: 0px;
        }

        .navbar {
            margin: 0px;
        }
    </style>

    <!-- jQuery and Bootstrap JS -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
    <div class="container-fluid first_wrapper">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">Admin Page</a>
                </div>
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#">Page 1</a></li>
                    <li><a href="#">Page 2</a></li>
                    <li><a href="#">Page 3</a></li>
                </ul>
            </div>
        </nav>
    </div>

    <div class="container-fluid" style="height:100%;width:100%;padding:0px;margin:0px;">
        <div class="row" style="height:100%;width:100%;padding:0px;margin:0px;">
            <div class="row" style="height:50%;width:100%;padding:0px;margin:0px;">
                <div class="col-lg-4" style="height:100%;background-color:red;"></div>
                <div class="col-lg-4" style="height:100%;background-color:green;"></div>
                <div class="col-lg-4" style="height:100%;background-color:pink;"></div>
            </div>
            <div class="row" style="height:50%;width:100%;padding:0px;margin:0px;">
                <div class="col-lg-4" style="height:100%;background-color:green;"></div>
                <div class="col-lg-4" style="height:100%;background-color:red;"></div>
                <div class="col-lg-4" style="height:100%;background-color:blue;"></div>
            </div>
        </div>
    </div>
</body>

</html>

Any content following the "Second Container" comment should automatically adjust its height accordingly.

Answer №1

Exploring the use of display:table was a good start, but for optimal styling, it's important to delve deeper into setting row and cell styling as well. By incorporating rows with display:table-row and designating the elements within container-fluid as display:table-cell, you can ensure that they occupy the necessary space without overflowing. Additionally, managing the white space created by tabbed HTML can be addressed by setting the body element's font-size and line-height to 0 and then resetting these values within the inline-block element. Keep in mind that using col-lg-4 necessitates widening the JSFiddle window for proper column display.

display:inline-block frequently leaves gaps between items due to whitespace in formatted code. To address this issue, techniques like using comments, skipping closing tags, or adjusting font size can be applied. While using display:inline-block for the containing element is preferred over display:table primarily because of a Firefox bug, solutions are available to overcome this rendering problem.

For further details, check out this informative article. As always, maintaining consistent font size tends to be the most straightforward approach to handling spacing concerns.

To view the demonstration on JSFiddle, click on the following link: JSFIDDLE

HTML

<div id="outerContainer">
    <div class="display-table">
        <div class="display-table-row" id="navigation">
            <div class="container-fluid first_wrapper display-table-cell">
                <!-- Navbar start -->
                <nav class="navbar navbar-default">
                    <div class="container-fluid">
                        <div class="navbar-header">
                            <a class="navbar-brand" href="#">Admin Page</a>
                        </div>
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="#">Home</a></li>
                            <li><a href="#">Page 1</a></li>
                            <li><a href="#">Page 2</a></li>
                            <li><a href="#">Page 3</a></li>
                        </ul>
                    &\<br>         
                </nav>
                <!-- Navbar end -->
            </div>
        </div>
        <div class="display-table-row">
            <div class="container-fluid display-table-cell">
                <div class="row">
                    <div class="col-lg-4" style="background-color:red;"></div>
                    <div class="col-lg-4" style="background-color:green;"></div>
                    <div class="col-lg-4" style="background-color:pink;"></div>
                </div>
            </div>
        </div>
        <div class="display-table-row">
            <div class="container-fluid display-table-cell">
                <div class="row">
                    <div class="col-lg-4" style="background-color:green;"></div>
                    <div class="col-lg-4" style="background-color:red;"></div>
                    <div class="col-lg-4" style="background-color:blue;"></div>
                </div>
            </div>
        </div>
    </div>
</div>

CSS

html,
body {
    height: 100%;
    padding: 0px;
    margin: 0px;
    font-size:0;
    line-height:0;
}

.first_wrapper {
    padding: 0px;
    margin: 0px;
}

.navbar {
    margin: 0px;
}

#outerContainer{
    display: inline-block;
    height:100%;
    width:100%;
    font-size:14px;
    line-height:1.42857143;
}
.display-table{
    display:table;
    height:100%;
    width:100%;
}
.display-table-row{
    display:table-row;
    width:100%;
    height:50%;
}
.display-table-cell{
    display:table-cell;
    width:100%;
}
.display-table-cell > .row{
    height:100%;
}
.display-table-cell > .row > [class*="col-"]{
    height:100%;
}
#navigation.display-table-row{
    height:auto;
}

Answer №2

Are you interested in implementing this?

https://i.sstatic.net/9CjRu.png

You need to utilize this Content Delivery Network (CDN)

<!-- Use the latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Use the latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
this is the complete script

<!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>Admin</title>
    <!-- Use the latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <style>
        html,
        body {
            height: 100%;
            padding: 0px;
            margin: 0px;
        }

        .first_wrapper {
            padding: 0px;
            margin: 0px;
        }

        .navbar {
            margin: 0px;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Use the latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
    <div class="container-fluid first_wrapper">
        <!-- Start of Navbar -->
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">Admin Page</a>
                </div>
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#">Page 1</a></li>
                    <li><a href="#">Page 2</a></li>
                    <li><a href="#">Page 3</a></li>
                </ul>
            </div>
        </nav>
        <!-- End of Navbar -->
    </div>
    <!-- Second Container -->
    <div class="container-fluid" style="height:100%;width:100%;padding:0px;margin:0px;">
        <div class="row" style="height:100%;width:100%;padding:0px;margin:0px;">
            <div class="row" style="height:50%;width:100%;padding:0px;margin:0px;">
                <div class="col-lg-4" style="height:100%;background-color:red;"></div>
                <div class="col-lg-4" style="height:100%;background-color:green;"></div>
                <div class="col-lg-4" style="height:100%;background-color:pink;"></div>
            </div>
            <div class="row" style="height:50%;width:100%;padding:0px;margin:0px;">
                <div class="col-lg-4" style="height:100%;background-color:green;"></div>
                <div class="col-lg-4" style="height:100%;background-color:red;"></div>
                <div class="col-lg-4" style="height:100%;background-color:blue;"></div>
            </div>
        </div>
    </div>;

</body>

</html>

Answer №3

You can implement CSS calc to adjust the height of the container while excluding the navbar height.

<div class="container-fluid first_wrapper">
    <!-- Navbar start -->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">Admin Page</a>
            </div>
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">Page 1</a></li>
                <li><a href="#">Page 2</a></li>
                <li><a href="#">Page 3</a></li>
            </ul>
        </div>
    </nav>
    <!-- Navbar end -->
</div>
<!-- Second Container -->
<div class="container-fluid full">

        <div class="row half">
            <div class="col-lg-4" style="background-color:red;"></div>
            <div class="col-lg-4" style="background-color:green;"></div>
            <div class="col-lg-4" style="background-color:pink;"></div>
        </div>
        <div class="row half">
            <div class="col-lg-4" style="background-color:green;"></div>
            <div class="col-lg-4" style="background-color:red;"></div>
            <div class="col-lg-4" style="background-color:blue;"></div>
        </div>

</div>

CSS:

.full {
    height: calc(100% - 52px);
}

.half {
    height: 50%;
}

.half > .col-lg-4 {
    height: 100%;
}

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 onKeyUp event is not functioning as expected in React, unlike the onChange event

For a React coding challenge, I am required to update a value onKeyUp instead of onChange. However, after changing it to onKeyUp, my fields are not updating and I cannot type anything into the textarea. class MarkdownApp extends React.Component { constr ...

Tips for effectively making REST requests from a ReactJS + Redux application?

I'm currently working on a project using ReactJS and Redux, incorporating Express and Webpack as well. I have successfully set up an API and now need to figure out how to perform CRUD operations (GET, POST, PUT, DELETE) from the client-side. Could so ...

Issue with Error in Expanding Label in Material-Ui using React

I have managed to increase the size of the Label in the TextField component of my React application. However, I am encountering an issue where it overlaps some text on its right when it shrinks. https://i.sstatic.net/BikHJ.png Here is the link for refere ...

Selecting menu items in React Material UI with various background colors using the RAL color selector component

Seeking a solution to create a component for selecting RAL colors using Material UI's TextField and MenuItem. Each item in the menu should have a background color reflecting the RAL color it represents. However, Material UI no longer supports inline s ...

Tips for concealing the "maxlength" attribute in HTML

Here is the code snippet I currently use on a signup and login form to restrict users from entering more than a specified number of characters: $( "#limit1" ).attr('maxlength','11').on('input', function() { if ($(this).val(). ...

JavaScript allows for the manipulation of elements within a webpage, which includes accessing elements from one

There is a file that contains a fragment for the navbar. The idea is to have listItems in the navbar, and upon clicking on those listItems, another subnavigationbar should open below it. Below is the code I currently have: <!DOCTYPE html> <html x ...

What is the correct way to send parameters in the action tag?

Can I set the res variable as the form action in HTML? <script> var name =$("#name").val(); var file =$("#file").val(); var res= localhost:8080 + "/test/reg?&name="+name+"&file=" +file ; </script> <form acti ...

iOS hover menu behavior: Close dropdown when the same element is tapped again on iPads

The navigation bar features categories such as: politics, economy, education Upon clicking on these categories, a dropdown menu appears with locations like: asia, europe, North America What I am looking for is this: If the user clicks (tabs) or hovers (o ...

Encountering the message "Error: Unable to access undefined properties (reading 'username')" while making my POST request

My POST request isn't functioning correctly and it's failing to update. The specific error message I'm encountering is: TypeError: Cannot read properties of undefined (reading 'username') app.post('/create-user', functio ...

What steps can be taken to ensure that an element does not exceed the boundaries of its grandparent container?

I am facing a unique scenario where I have a div with dynamic content, and inside it is another div containing a growing list. The challenge is to allow the internal div to expand until the root div reaches its maximum height, after which overflow should ...

Guide on displaying the name attribute of a button along with its price in a separate div when clicked

Upon clicking the Koala button, I want to display a message showing the id name of the button and the corresponding price for Koalas. Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <link h ...

Interactive Geography Selector

When updating your personal details on , you are required to choose your country first. Once the country is selected, the system automatically adjusts the city and/or state options based on that specific country's requirements. Can someone provide exa ...

Width and left values don't play well with absolute positioning

I am encountering an issue where a div with absolute positioning, which is a child of another absolute positioned element, is not behaving as expected. Despite setting width:100%; left:1px; right:1px on the child element, it extends beyond its parent. < ...

Problem with styling a CSS table

I am having an issue with the table style. My goal is to set the table radius to 8px, but my code doesn't seem to be working. Can someone assist me with this? Thank you! //ps I also require border-collapse in my code. Here is the link to my jsfidd ...

Is there a way to eliminate the space between the content inside a table cell and its borders?

I am struggling with a table setup that includes three columns and multiple rows. The first column contains an image, causing the cells in that row to resize based on the image size. When text is added to the 2nd and 3rd columns, it automatically centers w ...

Grails Error: Cannot find method signature for org.apache.catalina.core.ApplicationHttpRequest.getFile()

Every time I try to access the upload page of my Grails application, I encounter this error message: No signature of method: org.apache.catalina.core.ApplicationHttpRequest.getFile() is applicable for argument types: (java.lang.String) values: [file] ...

How can I apply a specific style class to a table row when I already know the table's id?

Hi there! I'm new to jquery and trying to enhance the functionality of my application which has multiple HTML tables in JSP's. My goal is to use jQuery to dynamically apply a CSS style class when hovering over a row. Currently, I have the followi ...

JSON retrieval line

Hi there, this is my first time posting here so I hope my question is clear :-) I have a PHP page that retrieves JSON data from a remote website. This JSON includes a list of names, and for each name, I need to fetch additional details from another JSON p ...

how can I transfer model values to a dashboard in Rails 5?

I have developed an app that includes an adminlte dashboard. The dashboard is populated with various values obtained by a jQuery file. I am trying to pass module values to the dashboard. For example, the number of users shown in the dashboard should be fet ...

Data is not being stored in Parse

I am currently facing a challenge while working with Parse for Javascript: When users sign up, along with their username and password, I also need to save their first and last names in Parse. However, at the moment, only the username and password are bein ...