Tips for achieving full width with Bootstrap

Recently, I delved into the world of bootstrap and encountered some trouble setting my width to 100%. Despite trying to assign width:100%; in my container CSS, it didn't seem to work. The only workaround I found was using container-fluid no-padding in my div class (which did work), but I learned that this approach is not recommended as it goes against Bootstrap's default 15px padding. What is the proper method for achieving a width of 100% in Bootstrap? Thank you in advance.

Here is the HTML code snippet:

.con-1{
    border: 1px solid green;
    height: 100%;
    position: absolute;
    left: 0%;
}

.row-1{
    border: 3px solid red;
    background-color: white;
    height: 75%;
}

.row-2{
    border: 3px solid red;
    background-color: white;
    height: 25%;
}

.col-1{
    border: 3px dotted blue;
    width: 95%;
}

.col-2{
    border: 3px dotted blue;
    width: 5%;
}

.col-3{
    border: 3px dotted blue;
    width: 31.6%;
}

.col-4{
    border: 3px dotted blue;
    width: 31.6%;
}

.col-5{
    border: 3px dotted blue;
    width: 31.6%;
}

.col-6{
    border: 3px dotted blue;
    width: 5%;
}
<div class="container con-1">
  <div class ="row row-1">
      <div class="col-lg-11 col-md-11 col-1">
          Row 1 Col 1
      </div>
      <div class="col-lg-1 col-md-1 col-2">
          Row 1 Col 2
      </div>
  </div>
  <div class ="row row-2">
      <div class="col col-3">
          Row 2 Col 1
      </div>
      <div class="col col-4">
          Row 2 Col 2
      </div>
      <div class="col col-5">
          Row 2 Col 3
      </div>
      <div class="col col-6">
          Row 2 Col 4
      </div>
  </div>
</div>

Answer №1

There are multiple ways to accomplish this goal.

If you desire a completely full-width element, simply apply the w-100 class to your div without using the container.

In your specific scenario, if you are utilizing a container, switch it to a fluid container by replacing it with container-fluid, and include a p-0 class as well.

For more information, check out the Bootstrap documentation: Spacing, Containers

Answer №2

Following @pete's recommendation, using the container-fluid class instead of container will resolve this issue and ensure the container width is set to 100%.

<div class="container-fluid con-1">
  <div class ="row row-1">
      <div class="col-lg-11 col-md-11 col-1">
          Row 1 Col 1
      </div>
      <div class="col-lg-1 col-md-1 col-2">
          Row 1 Col 2
      </div>
  </div>
  <div class ="row row-2">
      <div class="col col-3">
          Row 2 Col 1
      </div>
      <div class="col col-4">
          Row 2 Col 2
      </div>
      <div class="col col-5">
          Row 2 Col 3
      </div>
      <div class="col col-6">
          Row 2 Col 4
      </div>
  </div>
</div>

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

Steps to resolve the 'Unknown keyword' issue while packaging a CSS file using webpack

In the process of upgrading dependencies to the latest versions for my Electron app built in Angular, I have encountered some issues. ✅ Electron remains on v19 ✅ Tailwindcss is updated to v3.1.8 ⬆️ Angular is being upgraded from v11 to v14 ⬆️ ...

Learn how to toggle multiple class elements with jQuery, and how to hide the ones that have

This is an example of my HTML code: <h4 class="list-group-item-heading"> @Model.Customer.FirstName @Model.Customer.LastName wrote: <span class="right"><span class="icon-file padding-right link"></span></span> </h4& ...

Using the "align" attribute is considered outdated and not recommended in HTML5 documents

I have encountered an error when using the align attribute. How can I fix this issue with the correct HTML5 compatible syntax? <table style="margin: 0 auto;"> <tbody> <tr> <td><input typ ...

Choose a single dynamic image from a collection of multiple images

In the process of developing a Shopping cart website, I encountered an issue regarding allowing users to upload multiple images of a single product. Using jQuery, I successfully cloned the file input section to enable uploading additional images of the sam ...

Encountering an issue while attempting to replicate the Spotify app on localhost:3000. The error message "TYPEERROR: Cannot read property 'url' of undefined" is hind

As a first-time user of stackoverflow, I am unfamiliar with its rules and regulations, so I apologize in advance for any mistakes I may make. Currently, I am attempting to create a Spotify clone using React. Everything was going smoothly until I completed ...

What is the method to assign a value to ng-class in Angularjs?

I need to categorize items in a list by assigning them classes such as items-count-1, items-count-2, items-count-3, items-count-4, based on the total number of items present. This is how I would like it to appear: li(ng-repeat="area in areas", ng-class=" ...

Access a webpage outside of your domain using htaccess and PHP functionality

When a request is made to my website like this: my1stdomain.com/request-1/ my1stdomain.com/any-another-request/ The corresponding web pages should open on: my2nddomain.com/folder/request-1.php my2nddomain.com/folder/any-another-request.php To achie ...

How can I set the input tag to reset back to 1 when a certain event occurs?

I am currently developing an HTML Snakes And Ladders game. On the settings screen, there is an input field where users can select the size of the board. Depending on their choice, they will be able to choose a maximum number of snakes and ladders. For exa ...

Switching a conditional className to a styled component

Currently, I am in the process of converting my project from plain CSS to styled components using styled-components. So far, I have successfully converted all of my components except for one. I have looked at various examples on Stack Overflow but none of ...

Why is Bootstrap 4 causing these columns to stack vertically instead of horizontally?

After upgrading to bootstrap 4, I noticed that my gallery layout has changed from horizontal in bootstrap 3 to vertical. What could have caused this sudden change? To see the issue, here is a link to a fiddle. Here are my column settings: <div class= ...

Overlap with upper picture formatting

I've been struggling to create an ion-card with two images: a main picture and a small book cover. Any ideas on how to achieve this? Note: The layout should have 2 images, one at the top and another as a small book cover. Check out this sample on St ...

The fillOpacity and opacity properties appear to be malfunctioning

Note: While I understand that image masking can solve my issue, I prefer not to use it as it would require me to use my image as a background and could present accessibility challenges. I am specifically looking for solutions involving clip-path. Issue: T ...

The Reason Behind Angular Error when Using CSS Custom Tags

I have the following SCSS code: main{ width: 100%; height: 840px; /*background: red;*/ margin: 10px auto; position: relative; padding: 5px 0; } section{ width: 98%; height: 600px; margin: auto; display: flex; ...

What is the reason behind the issue where max-height disrupts border-radius?

My inline svg is styled with the following CSS: .img { border-radius: 15px; overflow: hidden; max-width: 70vw; margin-top: 6vh; max-height: 50vh; z-index: -1; text-align: center; } Everything seems to work as expected, except f ...

Tips for creating a custom Menu with content overflow in a single direction

What is the goal of this task? I have developed a custom Menu in my application with 8 options. There is a need to dynamically disable certain menu options based on specific conditions (e.g. disabling the last 4 options). When a user hovers over a disable ...

My HTML table is not printing at full width

Seeking assistance with creating a printable calendar using an HTML table. The calendar prints perfectly on a Mac, but when attempted on Windows in all browsers, it adds a 3" margin at the top regardless of CSS print settings. The client requires the cal ...

Applying Border Radius to JavaFX Components for a Unique Background Effect

When I apply the CSS properties -fx-border-radius and -fx-border-width to a basic GridPane, the background in the corner does not get "cut off". The following is the CSS code being used: .payload { -fx-hgap: 20px; -fx-padding: 40px; -fx-back ...

Switch the secondary menu to be the main menu on all pages excluding the homepage in WordPress

I am looking to customize my menu display by showing the primary menu only on my home page (front-page.php) and displaying the secondary menu on all other pages except for the home page. In my functions.php file, I have registered both the primary and sec ...

Unable to generate webpage source code

Having some trouble with my Next.js project as I'm using getStaticProps and getStaticPath to build a page, but unfortunately, the HTML is not being generated in the page source. This issue is causing problems with SEO, and I haven't implemented r ...

Styling with CSS based on the remaining width of the viewport relative to the height

If you're viewing this on a tablet browser, the dimensions are set relative to the viewport width and height. Let's assume a landscape orientation for simplicity. Inside a fullscreen container, there are two divs positioned absolutely, just like ...