Fluid container with two columns using Bootstrap 3's container layout

I am currently working on designing a container with a two-column layout using the container-fluid class for background color and image requirements. Inside this container, I have included a container class to ensure that the content aligns properly with non container-fluid containers. My main objective is to achieve alignment within a full-width column structure featuring two different background colors.

For visual reference, you can view an example of what I am aiming to create by clicking on the following link: https://i.sstatic.net/hNaUQ.png

Below is the code snippet representing my current progress on this project:

.flex { display: flex; }

.container-fluid { background: #fff; }
  .container-fluid .col-sm-6:last-of-type { background: #000; color: #fff; }

  .container-fluid .container { width: initial; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
  <div class="row">
    <div class="col-xs-12">
      <p>This represents a container class. The content below should align with the content of these containers.</p>
    </div>
  </div>
</div>


<div class="container-fluid">
  <div class="row flex">
  
    <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-0">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h4>Column 1</h4>
            <p>The content in this section needs to align with the container class mentioned above.</p> 
          </div>
        </div>
      </div>
    </div>
    
    <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-0">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h4>Column 2</h4>
          </div>
        </div>
      </div>
    </div>
    
  </div>
</div>

Answer №1

Each row class will now apply a -15px margin on both the left and right sides, while each col-* class will add a 15px padding to both the left and right sides. It is crucial that these combinations are correctly matched. I have removed offset classes that were causing misalignment; feel free to reintroduce them if necessary. Hopefully, this solution resolves any alignment issues you were experiencing.

.flex {
  display: flex;
}

.container-fluid {
  background: #fff;
}
.container-fluid .col-sm-6:last-of-type {
  background: #000;
  color: #fff;
}

.container-fluid .container {
  width: initial;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container-fluid">
  <div class="row">
    <div class="col-xs-12">
      <p>
        This container class should align its content properly.
      </p>
    </div>
  </div>
</div>

<div class="container-fluid">
  <div class="row flex">
    <div class="col-xs-10 col-sm-6">
      <div class="row container">
        <h4>Column 1</h4>
        <p>
          The content within this column should align with the container class above it.
        </p>
      </div>
    </div>

    <div class="col-xs-10 col-sm-6">
      <div class="container row">
        <h4>Column 2</h4>
      </div>
    </div>
  </div>
</div>

Answer №2

Kindly ensure to update the path for your bootstrap CSS file.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

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 create interactive canvases that respond to multiple clicks using JavaScript?

Within the canvas, the code snippet below aims to generate a grid of 10x10 colored boxes with alternating reddish and bluish shades on a gray background. The intention is for each canvas to only respond to mouse interactions when the mouse is within its bo ...

Combine the elements within the HEAD tag into a group

I am currently developing a dynamic page system using AJAX. Whenever a link is clicked, an AJAX call is made to retrieve data from the requested page. However, I have encountered an issue where certain data in the page file needs to be placed within the h ...

The post page remains out of reach for Ajax

I've been struggling for hours to identify the issue with this code. I realized that I am unable to access the updateuser.php file even though it is in the same directory and the filenames are correct. Can someone please review the code below and let ...

IntelliSense in VS Code is unable to recognize CSS files

I'm currently in the process of creating a React application, however, I've encountered an issue where importing a .css file doesn't prompt vscode to display the file in the intellisense feature. https://i.sstatic.net/nxhyV.png It's u ...

Is it possible to add border radius to the scrollbar in Firefox?

I'm trying to make the scroll bar in Chrome compatible with Firefox, but I can't figure out how to give it a border radius. Chrome scroll bar css /* Store selector */ /* width */ .lhh::-webkit-scrollbar { width: 6px; height: 56px !important ...

What is the best way to trigger the Bootstrap datepicker in an AngularJS application?

Can you please guide me on how to implement the bootstrap datepicker in an AngularJS application? I have two fields - name and date. I would like the datepicker to appear when the user clicks on the date field. Here is a snippet of my code: http://plnkr.co ...

Changing URLs to Exclude .html Extension

Consider this idea: eliminating the .html extension from all pages on the website, like this... www.website.com/File.html > www.website.com/File www.website.com/Folder/File.html > www.website.com/Folder/File Although I've successfully accompli ...

Using Vue to toggle an active HTML class on click: A tutorial

Can someone assist me with this code snippet that is intended to toggle a class using a Vue on-click event? I'm encountering issues as it's not working and I'm seeing several errors in the console. Any help would be appreciated. <div id=& ...

I am attempting to align a column to the right side

Currently experimenting with bootstrap 4, particularly using col and row. I am attempting to float a section of the contact form to the right side. I have attempted justify-content-end, float: right, and various other styles but none seem to work. As I am ...

Incorporate a FontAwesome Icon into your jsPdf Document

I recently updated to the latest version of jspdf.debug.js. Unfortunately, when I try to render FontAwesome icons in a PDF document, they are not displaying properly. I have added a user icon using FontAwesome on my webpage and included an image for refer ...

What is the best way to navigate a static dual navigation bar?

I'm currently working with two fixed and responsive navbars. Below is the code I'm using: function myFunction() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { ...

Centralize and confine the menu division

I have been working on creating a hover menu using CSS and Bootstrap, specifically for flex grid layouts. However, I have run into an issue where my menu is only as wide as its parent div. Furthermore, I am struggling to center the hover menu relative to ...

On a desktop view, the content is displayed in 4 columns, while on smaller

In my simple block, I am trying to arrange 4 items in a row on desktop and 2 items per row on smaller devices like tablets and mobile. The desired layout is shown below: https://i.sstatic.net/3i799.png To see a live demo, visit: jsfiddle Below is the HTM ...

When using classList.replace, it should swap out every instance of the class xxx1yyy with xx

I attempted to swap a class and came across this helpful example here: javascript: replace classList that is inside a conditional Unfortunately, my attempt at modification (shown below) did not work. The use of classList.replace should change all instanc ...

When converting the .html file to a .php file, the CSS file fails to be linked correctly

The issue I'm facing seems to be specific to the index.html file. The CSS that functions properly with an html extension suddenly stops working when the extension is changed to php. Upon inspecting the reference link in both cases, I noticed that when ...

Trigger the onsubmit function in an HTML form exclusively when the submit button is clicked

By clicking the plus icon, both submitFunc() and meanFunc() functions are currently executed. However, I want to modify it so that submitFunc() is only triggered when the Submit button is pressed. function submitFunc(e) { alert('submit') } ...

Utilizing Piwik Analytics in jQuery Mobile Framework

Having an issue with tracking users on my mobile Web App using Piwik. Due to AJAX, only views on the first page are being tracked. I attempted to use the pageinit function to load the Piwik tracking script on every page, but it still only tracks the firs ...

What's causing my CSS layout to get disrupted by this PHP script?

This website utilizes the $_GET method to extract an asset ID and query a MySQL database for information retrieval. If the 'id' does not correspond to any record, no results are displayed but the page layout remains unaffected. However, if &apos ...

Despite following all the correct steps, the tailwind CLI remains unresponsive. Additionally, the default button fails to display any content

view the document and my packages (image) Although it worked with the cdn, I'm puzzled why I can't use it properly with the cli ...

Connecting CSS Style Sheet to JSP Page

I'm facing an issue with linking a CSS file located in my WEB-INF folder to a JSP page. In the JSP page, I have specified the location of the CSS file as follows: <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/WEB- ...