Increase the gap between columns within a Bootstrap 4 grid system

Looking for some help with my code snippet below:

<% include partials/header %>

<div class="container">

    <header class="jumbotron">
        <div class="container">
            <h1>Welcome to YelpCamp!</h1>

            <p>View our handpicked campgrounds from all over the world!</p>

            <p><a class="btn btn-primary btn-large" href="/campgrounds/new">Add New Campsite</a></p>
        </div>
    </header>

    <div class="row text-center" >
        <% campgrounds.forEach(function(campground){ %>
            <div class="col-lg-3 col-md-4 col-xs-6 img-thumbnail p-0 ">
                <img class="img-fluid" src="<%= campground.image %>">
                <caption> <%= campground.name %> </caption>
            </div>
        <% }) %>
    </div>

<a href="/">Back</a>
</div>


<% include partials/footer %>

I have a list of campgrounds that I'm displaying in a Bootstrap grid, but the columns don't have any spacing between them. In Bootstrap 4, the automatic gaps from using thumbnails in Bootstrap 3 are not available. I tried adding margin mx-3 to the

`class="col-lg-3 col-md-4 col-xs-6 img-thumbnail"`

However, this adds to the total width and shifts the last item. Any suggestions on how to add spacing between the columns while maintaining alignment?

Answer №1

Utilizing Bootstrap 4 allows for automatic spacing, as long as you select the appropriate components based on your specific requirements.

In this scenario, the ideal component to use would be the figure component with the classes figure-img img-thumbnail applied to the images.

When adding image captions, it is recommended to use the following structure:

<figcaption class="figure-caption">Your Image Caption</figcaption>

If you encounter an uneven number of thumbnails or include col-md-4 columns, applying the justify-content-center class to the row will center the thumbnails effectively.

To test the code snippet, click "run code snippet" below and expand it to full page view.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container">
   <header class="jumbotron pl-5">
       <h1>Welcome to YelpCamp!</h1>
       <p>View our handpicked campgrounds from all over the world!</p>
       <p><a class="btn btn-primary btn-large" href="/campgrounds/new">Add New Campsite</a></p>
   </header>

   <div class="row justify-content-center text-center">
       <div class="col-6 col-lg-3">
           <figure class="figure">
               <img src="https://placeimg.com/800/400/animals" class="figure-img img-thumbnail">
               <figcaption class="figure-caption">A caption for the above image.</figcaption>
           </figure>
       </div>
       <div class="col-6 col-lg-3">
           <figure class="figure">
               <img src="https://placeimg.com/800/400/people" class="figure-img img-thumbnail">
               <figcaption class="figure-caption">A caption for the above image.</figcaption>
           </figure>
       </div>
       <div class="col-6 col-lg-3">
           <figure class="figure">
               <img src="https://placeimg.com/800/400/tech" class="figure-img img-thumbnail">
               <figcaption class="figure-caption">A caption for the above image.</figcaption>
           </figure>
       </div>
       <div class="col-6 col-lg-3">
           <figure class="figure">
               <img src="https://placeimg.com/800/400/arch" class="figure-img img-thumbnail">
               <figcaption class="figure-caption">A caption for the above image.</figcaption>
           </figure>
       </div>
   </div>
</div>

It's important to note that nesting Bootstrap containers should be avoided unless absolutely necessary (which is almost never required).

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

Error: The element 'mdb-icon' is not recognized and cannot be parsed

I am currently utilizing Angular 7 alongside Bootstrap 4, and encountering the following error message in my console. Uncaught Error: Template parse errors: 'mdb-icon' is not a known element: If 'mdb-icon' is an Angular co ...

Is there a way to update the value of an element that is continuously changing through a setInterval() function when hovering the mouse over it?

I am currently a novice working on developing a pomodoro timer. At the moment, when you click the button to start the timer, it switches to displaying the remaining time once activated. One of the features I want to implement is the ability for users to h ...

Mobile FPS suffering due to slide-out drawer performance issues

My application features a drawer menu that functions smoothly on desktop, but experiences issues on mobile devices with noticeable lag. Within the header, I have implemented a boolean value that toggles between true and false upon clicking the hamburger i ...

Angular Material: Modifying Form Field Control - changing position of floating label

I have developed a custom form field control for Angular 8 that is compatible with Reactive Forms and Angular Material. This form control features a simplified rich-text editor with a header containing various buttons for user actions. Is there a way to r ...

What is the best way to horizontally center a div within an overflow scroll container?

https://i.sstatic.net/cuQFc.gif Check out what I've created. I attempted to center a yellow div horizontally within an overflowing div, and trigger this using the scroll event. However, as you can see, it's glitchy and behaves oddly. The issue ...

Hold off on scrolling up while hovering over the screen

I've been attempting to implement a scroll-up behavior in WordPress, but I'm facing difficulties in pausing the animation when hovering over it. I've experimented with both jQuery and CSS methods, but have not been successful so far. Any ass ...

Aligning the navigation bar items in Bootstrap 4 (version alpha 5)

I have been exploring ways to center the navbar content in Bootstrap 4, alpha 5. After some research, I came across a suggestion involving the use of d-block and mx-auto. However, I am struggling to figure out how to center the navigation links so that th ...

Scrollable Vertical Navigation Menu with Fly Out Feature implemented using only HTML and CSS

Hello there, just wanted to mention that I am new to this site so please bear with me if I fumble a bit. I'm sure I'll improve as I gain more experience. My aim is to create a vertical navigation menu using only HTML/CSS that can scroll and expa ...

I need the sidebar to be visible across all interfaces

https://i.stack.imgur.com/iEgAF.png I have developed a website for employee monitoring with six interfaces. The first interface is for sign-up, the second for logging in, the third for creating projects, the fourth for displaying projects, the fifth for c ...

Session availability extends to subdomains, even though it may not be visible in a physical

Currently in the process of building a website Red Sec using a single account for all subdomains: Latest Updates Community Forum Personal Blog News Feed Support Us All pages share the same layout with different content by linking them to . Below i ...

Troubles with Bootstrap package and bundling in ASP.NET Core

I have Visual Studio 2017 installed and recently downloaded the Bootstrap package. However, I'm unsure of the next steps to take. I am using the bundle file and package... Could you provide guidance on what I should do next? Additionally, I obtained ...

How to correctly position a modal in a React application using CSS

Currently, I am working on integrating the react-modal NPM library into a React Typescript project. The issue I am facing is that the modal occupies the entire width of the screen by default, with padding included. My goal is to have it display as a small ...

Issue with CSS transition bug in Offcanvas on Android version 4.1.x

I am attempting to develop an offcanvas menu similar to the one featured in the Google Plus app. Currently, my code functions properly on most devices (android/ios) and browsers (ff, chrome, IE8+). The only issue I am encountering is on a Samsung Galaxy ...

I am having trouble loading the .woff file

I have almost finished the design of my site, but I'm encountering a problem with installing and using a specific font. Do .woff files only display on the web once connected to a server? I'm quite confused about this. Despite following the provid ...

Strategies for creating a clickable dropdown menu

I am currently developing a website that requires 15 HTML files. I have created a navbar with 3 direct links nav-items and 2 dropdowns. How can I make the dropdown menu appear on hover instead of click, and navigate to the dropdown href link when clicked? ...

What is the best way to obtain the final HTML output once all scripts have been executed

Is there a way to obtain the final HTML after all scripts have been executed? The scripts on the page are adding and changing controls and CSS, and I want to see the HTML of the display as a static page. Is there a method to achieve this? Edit: For exa ...

What could be causing the GridView to not apply my CSSClass?

I am currently in the process of setting up a new web page using ASP.net. I have implemented a gridview with paging, but unfortunately, the CSS class I intended to use is not being applied correctly. While the rest of the page's CSS is functioning pro ...

What's the issue with the submit button not functioning on the form?

After downloading a sample form, I encountered the following code: <form id="login-user" method="post" accept-charset="utf-8" action="/home.html" class="simform"> <div class="sminputs"> <div class="input full"> <l ...

How can you specifically target the initial row of a CSS grid using Tailwind?

Currently in my vue application, I have a loop set up like this: <div class="grid grid-cols-3 gap-14"> <article-card v-for="(article, index) in articles" :key="index" :content="article" /> </div> ...

Tips for making Slider display the next or previous slide when span is clicked

I have implemented a mix of bootstrap 3 and manual coding for my project. While the image thumbnails function correctly when clicked, the span arrows do not navigate to the next or previous images as intended. Below is the code snippet: var maximages ...