Creating a foundational structure with Bootstrap 4 by nesting a container within a container-fluid

I'm utilizing bootstrap4 to construct a simple layout, and here's what I have so far...

.container-fluid {
    background: grey;
}

.container {
    background:wheat;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container-fluid">

    <div class="container p-5">
      
      <div class="row">
                                
          <div class="col-md-12 pb-5">
      
              <h1>My First Bootstrap Page</h1>      
              <p>This part is inside a .container-fluid class.</p> 
              <p>The .container-fluid class provides a full width container, spanning the entire width of the viewport.</p>

          </div>

      </div>
      
       <div class="row">
                                
          <div class="col-md-6 pb-5">
      
              <h1>My First Bootstrap Page</h1>      
              <p>This part is inside a .container-fluid class.</p> 
              <p>The .container-fluid class provides a full width container, spanning the entire width of the viewport.</p>

          </div>
          
          <div class="col-md-6 pb-5">
      
              <h1>My First Bootstrap Page</h1>      
              <p>This part is inside a .container-fluid class.</p> 
              <p>The .container-fluid class provides a full width container, spanning the entire width of the viewport.</p>

          </div>

      </div>

    </div>

</div>

I've opted for the container-fluid to ensure the background spans the full width, while nesting container inside for a maximum content width.

Is this approach correct? Any suggestions for achieving this layout more effectively?

Answer №1

Typically, it is not recommended to nest containers. Each section should only contain one container class (either .container or .container-fluid).

If you want the background to span full-width but have a maximum width inside, you can simply use <div /> or <section /> outside of the container. These elements have their width set to 100% by default:

<section class="bg-secondary">
    <div class="container">
        ...
    </div>
</section>

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

See demo here: https://jsfiddle.net/davidliang2008/0Ljkcmfn/5/

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

Validate if a certain value exists within an array of data using NgIf

Is there a way to verify the existence of a value in an array of data? gjhg = [ id, name ] ...

What is the best way to emphasize a table row during a search rather than just the text?

I am currently using a jQuery script that searches for a specific string in a simple text input field and highlights only the string itself if it is found. However, my data is organized within a table and I am interested in knowing if it is possible to hig ...

The placement of bootstrap 3 .nav element in the browser Internet Explorer 9

Having an issue with my navigation in Windows Explorer 9. It's supposed to be positioned under the site heading, which works fine in Chrome and newer versions of Internet Explorer. However, in IE 9 it appears over the main heading at the top of the pa ...

The HTML5 webpage is failing to send a JQuery Ajax request

I am encountering an issue with my Ajax setup on a HTML page. The call to a web service does not seem to be working as intended, and I suspect that the ajax call is not even reaching the web service at all. The problem arises when I click the button, an e ...

Incorporating a secure and personalized "tracking code" feature into a PHP web application

My web application is built using vanilla PHP and MySQL, allowing registered users to create personalized profile pages. I want to implement a textarea form field in the control panel for users to input their custom tracking code (such as Facebook Pixel o ...

Implementing real-time search functionality using API calls in Angular

Seeking guidance on implementing Typeahead for a global search feature in my app. When users type, it should call an API and display results in a drop-down menu. I am a beginner in Angular and Typescript, so any working examples with code would be greatly ...

What is the best way to design a horizontal collage using solely HTML5 and CSS3?

Is there a way to achieve a horizontal collage with equal spacing between pictures using HTML5 and CSS3? As a newcomer to HTML5, CSS3, and StackOverflow, I apologize if my post is a bit messy. Any help would be greatly appreciated. This is the desired de ...

When it comes to media queries for screen vs. iframe, it is

Currently facing a dilemma. I have a link that appears in an iframe when viewed on a computer, but displays on the parent page if accessed through a mobile device. For mobile users, I want to restrict access to the page only in landscape mode. To achieve ...

Implementing a jQuery change event to filter a specific table is resulting in filtering every table displayed on the page

I have implemented a change event to filter a table on my webpage, but I am noticing that it is affecting every table on the page instead of just the intended one. Below is the code snippet: <script> $('#inputFilter').change(function() { ...

Tips for highlighting the sticky subnav menu option as you scroll

Currently utilizing intersection observer to toggle the visibility of the sticky navbar and make the scroll bar sticky. I am now looking to add a feature where the sub nav options highlight with color as we scroll, focusing on the container with a specific ...

Adjusting the height of flex items to 100%

I'm currently diving into the world of flexbox by exploring various tutorials. Here's an example I created without utilizing Flex. Instead, I relied on float:left. Check out the example: https://jsfiddle.net/arhj8wxg/4/ I attempted to convert t ...

Using JavaScript to open links in a new tab with the target

document.getElementById("mahacareer").onclick = function () { window.open("http://www.mahacareermitra.in", '_blank'); }; <a href="" id="mahacareer">Access the portal</a> Hi there, I am looking to have the link above open in a new tab ...

How to Deactivate Navigation Tabs in AnythingSlider?

I am encountering some issues with the css and js while using the AnythingSlider tool. Specifically, I want to modify the navigation tabs in a way that certain tabs will either remain unchanged or become inactive based on a ColdFusion conditional. For ins ...

Overlaying content in a strategic and effective manner is key to maximizing

<div id="container"> <div>HEADER</div> <div>CONTENT</div> <div>FOOTER</div> <div><textarea></textarea></div> </div> <button>activate overlay</button> #cont ...

I am facing an issue where HTML is not loading images or some parts of my CSS in PHP

I've been working on connecting my website to a MySQL database using PHP. Initially, I thought I could keep the HTML and CSS the same, but after adding everything, the images on the website stopped showing up as they did before. The fonts and other el ...

What is the method for specifying the default option in a SELECT Tag and how can the Index of the chosen option be obtained?

Looking for HTML and JavaScript code that can manipulate SELECT and OPTION Elements. <select> <option> </option> <option> </option> </select> How do I retrieve the index of the selected option and obtai ...

Template Function Problem Detected in AngularJS Formatting

I'm struggling to incorporate my scope attributes into a template function within my custom directive. The formatting for the return section in my template is not working as expected. This is how it currently looks: angular .module(' ...

Angular Bootstrapped Navbar with Tab-style Links

I have been working on a project with a specific example: Routing example In my app.component.html file, I made a modification from: <ul class="nav nav-tabs"> to <ul class="nav nav-pills"> Now, the tabs have the appearance of pills. Next ...

What could be causing my CSS style to not take precedence over Bootstrap in this particular case?

I am struggling to make my CSS styles take precedence over Bootstrap's defaults for aligning table headers. Below is the code for my table: <table class="userProjectsTable" id="userLeadProjectsTable"> <tr class="userProjectsHeaderRow" i ...

Steer clear of utilizing CSS pseudo-elements like :before and :after

I am seeking a solution to hide a <label> when viewing on a small mobile device. Below is the HTML code: <label class="page_createpassword_label" for="page_createpassword"> <span class="page_label_main">Span Text</span> <span c ...