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?

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

Is there a workaround utilizing calc() and vh specifically for Chrome browsers?

Is it possible to find a CSS-only solution for incorporating vh in calc() functions specifically for Chrome browsers? I am trying to implement calc(100vh - 25px) as the top margin in order to make a 25px bar stick to the bottom of the page, but I am facin ...

Maintaining nth-child(odd) following filtering using jQuery

I am using a jQuery script to filter a table with multiple entries on this site. The filtering works well, but the issue arises when it comes to maintaining the correct tr:nth-child(odd) color that I have specified in my CSS. After filtering, the original ...

What is the preferred choice: using camelCase in CSS with Styled Components or Emotion for standard React development?

When I'm coding with React Native, I use the styled properties that follow most of CSS syntax and are formatted in camel case. For instance: //... <Component style={styles.container} /> //... const styles = StyleSheet.Create({ ...

Switching icon images using JQuery based on state changes

I'm attempting to switch the background image of my webpage's "body" element when the user toggles between playing and pausing music icons. This is what the CSS for the "body" element looks like: body { background: url('https://s3-us-wes ...

Is it possible to combine the :last-child pseudo-class with the universal selector (*) in CSS or Sass

Here is the code I am currently using: .loken5 * padding-right: 5px .loken5:last-child padding: 0 I am wondering if there is a way in SASS to achieve the same effect with just one '.loken5' tag for saving space. Thank you :) ...

Is it possible to display a Processing message at the beginning of a datatables table already containing data?

Within my Laravel 5.7 application, I have implemented the "yajra/laravel-datatables-oracle": "~8.0" library and found a helpful thread on customizing the processing message at this link. I adjusted the processing message styling as follows: .dataTables_pr ...

The navigation bar in responsive view on Bootstrap 4 causes the content below it to shift

Recently I have been exploring bootstrap-4 and encountered an issue while creating a nav-bar. The problem is that in responsive view, when toggling the nav-bar it simply pushes the content below it. Is there any way to address this issue within (bootstra ...

Sending Data via Ajax

I am currently working on implementing an ajax invitation script that allows users to invite their friends to an event. The javascript code I have used in other parts of the website works perfectly, but for some reason, it is not functioning correctly in t ...

How can we call a function in HTML from an external JavaScript file?

I am attempting to utilize a function that I have defined in my .js file within my HTML document. js/newsalerts.js function decodeHTML(html) { //https://stackoverflow.com/a/2989105/4650297 var tempDiv = document.createElement("DIV"); tempDiv. ...

Incorporating a navigation bar at the top and a sidebar on the left side of the lower half of an HTML webpage

Currently utilizing materializecss and bootstrap, I am aiming to create a design that resembles: --------------------------------- --------------------------------- | | | | The objective is to split the page into two horizontal sections. The ...

Implementing CSS Transform for Internet Explorer

Hello, is there a way to make this function in IE ?? I have been looking into IE transformations but it appears that they are not supported.. Is there an alternative method or something else? It works in other browsers like Firefox, Chrome, and Opera. I s ...

Determining the width of an element in terms of percentage

My issue involves input elements with widths set as percentages in CSS under the common class 'display-class' For example: input.test1 { width: 60% } In JavaScript, I am attempting to wrap a div around these input fields with the same width ...

Is it possible to partially move the image outside of the MUI dialog?

Is it possible to move an image partially outside of the MUI dialog, with the bottom part inside and the top part outside the dialog? I attempted a solution found on Stack Overflow but it did not yield the desired result. This is the dialog code: <Dial ...

Steps for converting a window to a PDF file rather than an XPS file

Whenever I attempt to print the contents of my HTML page using window.print(), it always creates an XPS file. However, what I really need is for it to generate a PDF file instead. Any assistance would be greatly appreciated. Thank you! ...

Incorporating Javascript jQuery functionalities from an external file

I have encountered an issue when trying to run my index.html file with the control.js file that I outsourced. It seems like they are not working together properly: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.c ...

Adjust Font Size inside Circular Shape using CSS/jQuery

I have been searching for different libraries that can resize text based on the size of a container. However, my container is circular and I am facing difficulty in preventing the text from overflowing beyond the border. Below you will find a Fiddle conta ...

Event object not being passed to function in UIWebView Javascript onclick event

When inserting HTML dynamically using simple NSStrings and then loading it into a UIWebview, the following approach is taken: [NSString stringWithFormat:@"<div onclick=\"MyClickEvent(e);\"....some more text here"> A function is defined li ...

Is there a way to display the output of jQuery in an input box rather than a span?

I need to display the result of this function in an input box instead of a span tag because I plan to utilize the result in the following form. function checkChange(){ $.ajax({ url: "ordercalculate.php", data: $('form').seria ...

Utilizing web components in React by solely relying on a CDN for integration

I have a client who has provided us with a vast library of UI elements that they want incorporated into our project. These elements are stored in javascript and css files on a CDN, and unfortunately I do not have access to the source code. All I have at my ...

The `required` attribute is ineffective when used with the `<form>` element

My required attribute isn't enforcing mandatory field completion before form submission. HTML Code: <!-- Modal Content --> <form class="modal-content2"> <div class="container3"> < ...