Are all the bootstrap columns displaying in a single row?

Despite my best efforts, I'm facing a puzzling issue as a newbie. I've meticulously set up the container > row > col structure in Bootstrap, but all my columns stubbornly remain on the same line. According to the Bootstrap guidelines, only 12 columns should be in each row, with any excess appearing on the next line.

Here's the HTML snippet causing me grief:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container-fluid">
      <div class="row m-3 p-3">
        <div class="col text-center">akjsdajkshd
        </div>
        [...]
      </div>
    </div>
</body>
</html>

I've spent hours trying to troubleshoot this apparent error to no avail. Any assistance would be greatly appreciated. Click here for an image describing my dilemma

Answer №1

For your convenience, I have replicated your scenario in a CodePen environment using the following setup:

<div class="container">
    <div class="row">
        <div class="col-sm">1</div>
        <div class="col-sm">2</div>
        <div class="col-sm">3</div>
        <div class="col-sm">4</div>
        <div class="col-sm">5</div>
        <div class="col-sm">6</div>
        <div class="col-sm">7</div>
        <div class="col-sm">8</div>
        <div class="col-sm">9</div>
        <div class="col-sm">10</div>
        <div class="col-sm">11</div>
        <div class="col-sm">12</div>
    </div>
</div>

As per Bootstrap's Grid system:

The provided example establishes uniform-width columns on small, medium, large, and extra large devices by employing our predefined grid classes. These columns are horizontally centered within the page through the parent .container.

When leveraging Bootstrap, there is no mandatory requirement to utilize container-fluid, unless you intend to apply width: 100% to the container across all breakpoints (varying device widths: Small ≥ 576px, Medium ≥ 768px, Large ≥ 992px, etc.). Check out Bootstrap's Container documentation here.

If you wish to assign text-center to all div elements, consider the following method to avoid unnecessary class additions:

<div class="container text-center">
...
</div>

I trust this guidance assists in resolving your issue! Feel free to inquire if further clarifications are needed 🙂

Answer №2

What's the purpose of using a fluid container in Bootstrap design for responsiveness? To understand this concept better, try making the following snippet full screen. You'll notice that when the grid exceeds 12 columns, it automatically moves to a new line.

<!DOCTYPE html>
<html lang="en>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container-fluid">
  <h1>Hello World!</h1>

  <div class="row">
    <div class="col-sm-4" style="background-color:lavender;">1</div>
    <div class="col-sm-4" style="background-color:lavenderblush;">2</div>
    <div class="col-sm-4" style="background-color:lavender;">3</div>
    <div class="col-sm-4" style="background-color:lavenderblush;">4</div>
    <div class="col-sm-4" style="background-color:lavender;">5</div>
  </div>
</div>

</body>
</html>

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

`NodeJS Compared to Static HTML`

I need to create a browser client for my Java Rest API and I'm considering the best approach with the least trade-offs. Should I use static HTML files with backbone to connect to the REST API and populate the data fields? Or should I opt for a NodeJ ...

Retrieving specific values for each key in JSON using PHP

Looking for a solution with PHP to extract specific information from JSON files based on set criteria. Here is an example of part of the JSON data: "Main": [{ "count": 7, "coordinates": [89,77], "description": "Office", },{ "count": 8, ...

Instructions on how to create a horizontal scrolling div using the mouse scroll wheel

I need help with scrolling a div horizontally using the mouse scroll button. My div does not have a vertical scroll and I would like users to be able to scroll horizontally. Can anyone provide guidance on how to achieve this? ...

Issue with closing collapsed menu on click in Bootstrap version 3

Here is the code snippet: <li> <a href="#" id="statics" class="main-bar"> <span class="glyphicon glyphicon-stats" aria-hidden="true"></span> </a> </li> I am trying to toggle the responsive menu on eleme ...

Performing a search in Django using raw MySQL commands

I am currently in the process of developing a custom search engine that includes 4 search fields, aiming to search within a MySQL table. This snippet from my views.py covers the search functionality, pagination, and listing of the entire table data. def ...

Show the final element in a list in a new and innovative style

How can I style the last item of a list differently? The issue is with the display of the last item in the list, which may go out of bounds on smaller screens. To ensure proper display, the list item "Argenti" needs to be shown in a single column. To ach ...

Limiting keyboard input with a phone number in a gridcolumn tag: A step-by-step guide

I have a query regarding a code line that is used to input a phone number into a designated box. <GridColumn field="phoneNumber" title="Phone Number" editor="text"/> Currently, I am able to enter any text using the key ...

PHP: Retrieving a selection value without the use of a submit button

I am trying to access and utilize the select value in my current PHP file, but without the use of a submit button. How can I accomplish this? Here is the code snippet I am working with: <?php $args = array( 'orderby' =&g ...

I am experiencing issues with the loading of CSS and JavaScript files in my recently created Laravel project

Recently, I received a Laravel project and successfully downloaded its configuration to get it up and running using php artisan serve. Upon attempting to access the project through localhost:8000, only the HTML content is displayed without any styling fro ...

Is there a way to determine the negative horizontal shift of text within an HTML input element when it exceeds the horizontal boundaries?

On my website, I have a standard HTML input field for text input. To track the horizontal position of a specific word continuously, I have implemented a method using an invisible <span> element to display the content of the input field and then utili ...

Press the button to duplicate the cell column separated by commas

In my HTML table, there is a specific column filled with container numbers that I want to copy to the clipboard when a button is clicked. The column has the class ".container" Here is the code I have been working on. HTML: <button onclick="copyToC ...

<ul><li>issue with indentation

Is there a way to eliminate the indent from my unordered list? While inspecting the element, I noticed what appears to be padding between the width of the box and the content. However, setting padding to 0px and margin to 0px doesn't seem to work as t ...

Issue: The d-inline-flex and flex-row-reverse combination in Bootstrap is malfunctioning

I am trying to achieve a specific layout in my HTML, as shown below: https://i.sstatic.net/fVUt1.png <p>Use .flex-row-reverse to right-align the direction:</p> <div class="d-inline-flex flex-row-reverse bg-secondary"> & ...

Limit the number of words in an HTML input box

Is it possible to set a maximum word limit for a textbox that a user can input, rather than limiting the number of characters? I did some research and discovered a way to determine the number of words a user has entered using regular expressions, but I& ...

Ways to activate a function upon validation of an email input type

Within my HTML form, there is an input type="email" field that requires a valid email pattern for acceptance. I am attempting to send an AJAX request to the server to confirm whether the entered email already exists in the database after it has been verif ...

prevent the page from scrolling to the top when clicking on an empty <a> tag

Is it possible to prevent the page from scrolling back to the top when a user clicks on an empty link tag using only HTML and without JavaScript? For example, if there is an empty link at the bottom of the page and a user clicks on it, the page jumps bac ...

Discovering the initial element with a data attribute above zero using JQuery

I am working with a set of divs that have the class .item-wrap. At the moment, I am able to select the first div using this code snippet: $(".item-wrap:first").trigger( "click" ); Each .item-wrap element comes with a data-amount attribute. My challenge ...

Break apart animation similar to the 🎊 emoji using CSS styling

I am attempting to create an animation of a circle splitting open on two sides, similar to the ...

Make the inner div within the td stretch to cover the entire height of the td

Inside the first tds, there is dynamic text content that automatically expands the trs and tds. However, the second tds have a div with a background image but no text inside. I want these divs with background images to expand or collapse along with the tab ...

Even with a correct XPath and the element present, Webdriver inexplicably throws a NoSuchElementException

There are 20 Google review score elements on a page like this. https://i.sstatic.net/9ErFS.png The XPath for each element is: //ol/div[2]/div/div/div[2]/div[%s]/div/div[3]/div/a[1]/div/div/div[2]/div/span To extract the review counts using Python and W ...