Images inside columns are not being properly displayed in a PHP for loop when using Bootstrap

I have created a bootstrap page in which I am attempting to showcase images inside bootstrap columns. Below is the code snippet that I have used:

<!DOCTYPE html>
<html lang="en">

<head>
  <title></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.6.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>

<body>



  <div class="row">
    <?php for($i=1;$i<=19;$i++){?>
    <div class="col-sm-12 col-lg-4" style="text-align:center">
      <img src="n<?=$i?>.jpg" class="img-responsive">
    </div>
    <?php } ?>



  </div>

</body>

</html>

Although there are 19 images and everything appears fine, there seems to be an issue with the 7th image displaying in a single row on larger screens. You can view the live link here: enter link description here.

If anyone could please point out what might be causing this problem, it would be greatly appreciated.

Answer №1

When working with code that utilizes bootstrap 3, flexbox is not the default option.

Using Bootstrap V3:

<div class="row" style="display:flex; flex-flow:row wrap;">
    <?php for($i=1;$i<=19;$i++){?>
    <div class="col-sm-12 col-lg-4" style="text-align:center">
      <img src="n<?=$i?>.jpg" class="img-responsive">
    </div>
    <?php } ?>
</div>

It's recommended to use bootstrap v4 or v5 as they have built-in support for flexbox, eliminating the need for additional CSS.

Bootstrap V4 and V5:

<div class="row">
    <?php for($i=1;$i<=19;$i++){?>
    <div class="col-sm-12 col-lg-4" style="text-align:center;">
      <img src="n<?=$i?>.jpg" class="img-fluid">
    </div>
    <?php } ?>
</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

What could be causing the appearance of a mysterious grey box hovering in the upper left portion of my image and why is the code only adjusting the size of the grey box instead of the entire

I've been working on embedding some JavaScript into my Showit website to create a drag-and-drop feature that displays a collage/mood board effect. Everything is functioning correctly, but I'm running into issues with resizing the images. There&a ...

Customize the website's CSS for optimal viewing on an iPad

I have a website with two CSS files: one for viewing the site on a desktop screen and the other for viewing it on an iPad screen. Despite having the same HTML code, is there a way to detect the iPad device and force it to use the appropriate CSS file? Tha ...

Adjust page to fit any size of screen resolution

Currently, I am in the process of designing a print template for my website. Everything seems to be going smoothly except for one issue that has arisen. The screen resolution on my device is 1600x900, so I have designed the page specifically for this resol ...

Updating the Hero Image

Scenario: In my project directory, under Product -> src -> static -> ostatic [ there are two folders named css and images ] -> images -> where all the images can be found. I am using bootstrap and attempting to set a background-image for j ...

The Django static CSS won't load properly on the webpage

Despite browsing various posts related to my issue, I have been struggling to resolve the problem at hand (for instance, following this informative post: Django static files (css) not working). The challenge lies in getting my static CSS file to load prope ...

Expand and collapse navigation menu using Jquery

I am currently working on a navigation list that should open and close when clicked. However, I am facing an issue where using nav ul li.test a to open the hidden ul on click is not working as expected. When I try using nav ul li.test without a, the hidd ...

Showing an incorrect rendering appearance, the styled <select> element in Bootstrap4 is not

I've incorporated Bootstrap into my website and noticed that the <select> elements look strange without any extra styling. I'm particularly concerned about the appearance of their arrows. Here's how a <select> element styled wit ...

JQuery HTML form validation continues to send emails even when there are blank entries

I've set up an HTML form with three required fields, and I'm trying to prevent the form from submitting an AJAX call if those fields are left empty. $("#contact").submit(function(e){ e.preventDefault(); var ajaxurl = '<?php echo ...

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 ...

creating an interactive image with Angular

I am experiencing difficulty in making my image clickable. The image is designed as a cart with a small number bubble indicating the quantity of items in the cart. Although the div itself is clickable, the photo within it is not. Below is my code snippet: ...

Issue with the left margin of the background image

I am currently facing an issue with a series of background images that are supposed to fade in and out behind my content. These images are centered, wider than the content itself, and should not affect the width of the page. However, there is an unexpected ...

Numerous elements positioned absolutely are overlapping

I am working on a website with a unique slide layout design. I am currently focusing on two specific slides: https://i.stack.imgur.com/xngF4.png and https://i.stack.imgur.com/W19tJ.png My goal is to include a button on each individual slide, similar to th ...

How can I make a div using jQuery fade in when an input field is in

I want to create a tooltip that changes its innerHTML and fades in when an input on my form is focused. Additionally, I need to check if the tooltip has been faded in as it initially loads faded out. In essence, I am looking to switch the tooltip content ...

Unable to unpack non-iterable NoneType object when trying to extract information from a Google search result using Django and BeautifulSoup

While working on my social networking Django site project, I attempted to use BeautifulSoup for searching Google. I downloaded it as an open-source and encountered an error message saying "cannot unpack non-iterable NoneType object" when trying to execute ...

How to prevent mousewheel scrolling on an HTML page with the exception of a specific div using jQuery

Is there a way to prevent mousewheel scrolling on an HTML page while still allowing it on a specific element? I've tried using the code below: $('html').bind("mousewheel, touchmove", function(e) { e.stopPropagation(); return false; ...

Horizontal Scrollbar on the Top and Bottom

I've spent the last few days searching for a viable solution to this particular dilemma. Basically, I have a div that requires a secondary scroll bar at the top in order to facilitate horizontal scrolling without having to navigate all the way to the ...

The art of rotating PDF files and various image formats

Looking for a way to rotate PDF and image files displayed on an HTML page using jQuery. I attempted: adding a CSS class - without success. Here is an example code snippet: .rotate90 { webkit-transform: rotate(90deg); moz-transform: rotate(90de ...

When utilizing *NgIf, the button will be shown without the accompanying text being displayed

When trying to display either a confirm or cancel button based on a boolean set in my component.ts, I implemented the following code in my HTML: <mat-dialog-actions class="dialog-actions"> <button class="cancel-btn" ...

Adjust the height of Fullcalendar when the window is resized to maintain the aspect ratio as it shrinks

I am having trouble adjusting the height of an FC (fullcalendar) within a div. My goal is to have the FC completely fill the div without overflowing. Despite setting the height attribute during initialization, the FC's height does not resize properly, ...

Dynamic images blending seamlessly with a fluid background aesthetic

Hello everyone, I could really use some assistance! My client is looking for a WordPress page with full screen backgrounds. Specifically, on one of the pages, they want 3 images placed on a fullscreen background image that remain in a fixed position while ...