What could be causing the significant gap at the bottom of my Flexbox?

Whenever I resize the page to fit a mobile device, there is always a large gap at the bottom.

I want the content to stack normally when it shrinks, without leaving a huge gap at the bottom.

There is no gap at the bottom when viewed on desktop, but as soon as I shrink it down, the stacking behavior introduces a big gap at the bottom.

This is what's happening in the image: https://i.sstatic.net/rRIRt.jpg

.song-box {
    width: 300px;
    margin: 20px;
    position: relative;
    vertical-align: top;

}

.flex-container {
    width: 1700px;
    display: flex;
    flex-wrap: wrap;
}


.flex-container img {
    opacity: 0.5;
}

.flex-container img:hover {
    opacity: 1;
}
<div class="flex-container">
        <div class="song-box">
            <img src="https://pro2-bar-s3-cdn-cf6.myportfolio.com/0d5a2028d7a7f8febf676a97648ea300/05851b218f8801ca2b106119_rw_1920.jpg?h=3e70946439d6e6326c1bd3efc5d20e51"
                alt="Nature" style="width:100%" onclick="myFunction(this);">
        </div>

        <!-- More similar code blocks here -->

</div>

the body

body {
    margin: 0;
    padding: 0;
    background: url(/images/party.jpg);
    /* background-size: 100%; */
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
    background-size: cover;
}

Answer №1

The issue with the gap at the bottom of the container appears to be due to the background image that is currently in use.

Answer №2

Eliminate the

background-attachment: fixed;

and ensure that the height remains set to auto for the background image. It seems like the background image should be determined by its content.

Additionally, specifying a fixed width will cause the box to overflow to the right. This prevents flex-wrap from triggering because even though the viewport is smaller, the box remains at 1700px. I recommend using

.flex-container {
    max-width: 1700px;
    display: flex;
    flex-wrap: wrap;
}

This should allow it to properly wrap, giving you space at the bottom.

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

Implementing Image Data in AngularJS: A Guide to Binding Images to IMG Tags

Allow me to explain the problem further. I am retrieving a user's profile picture by calling an API that returns image data, as shown in the screenshot below https://i.stack.imgur.com/t8Jtz.jpg https://i.stack.imgur.com/pxTUS.png The reason I canno ...

How can you identify the specific HTML page that a jQuery selector is targeting?

In an attempt to create jQuery code that counts the number of <img> elements on a website, I encountered a unique challenge. The website consists of 4 separate HTML pages stored in the same folder on the server. Among these pages, only "pics.html" is ...

What could be causing my PHP code to not execute properly alongside the HTML?

I am currently sharpening my skills in PHP by working on a simple web form project. To put it simply, I need to develop a basic web form that accepts a two-dimensional array of European cities along with the distance in kilometers between each pair of citi ...

Sending a post request in PHP

Having an issue with a basic post form functionality where the data is not being transmitted correctly. After hitting submit, the process.php file is stating that no username and password have been entered. It seems like there may be a simple mistake that ...

Tips for selectively applying CSS to a single HTML file

I'm currently working on a website utilizing AngularJS and Plangular to develop a unique Soundcloud Player. This is how I incorporate my template: <body> <div id="container"> <div id="header" ng-controller="HeaderCtrl"><div ...

Automatically select a radio button upon loading the page

Below is the code I am currently using: jQuery('#choice_1_10_3_1').attr('checked','checked'); I need this radio button to be checked automatically when the page loads. Despite no errors being shown in the console, the code i ...

Using CSS with absolute positioning and dynamic height

There are 4 consecutive <div> tags in absolute position, aligned using top and left. The third div tag has dynamic content, causing its height to adjust based on the text within it. However, since the top and left properties are set for all divs, th ...

Shifting text higher to the <h1> tag using CSS

I'm currently attempting to move the paragraph header closer to my h1 title. I'm struggling with incorporating the position function and have tried using padding without success. On the image, I am aiming to position the text "Where every connec ...

Using CSS to create shape gradients

I've been attempting to replicate the shape gradient found on Laracasts for hours, but unfortunately, my code isn't displaying anything. Can anyone lend a hand? a{ background: linear-gradient(118deg,#328bf2,#1644ad); border-radius: 54% ...

A web address shared in a post appears within the nested frame of an iframe

I'm encountering a somewhat confusing issue. I am attempting to submit a URL to an iframe located on the same page. Upon clicking submit, the iframe replicates the current page, but with the correct URL displayed in the duplicated iframe. It's ma ...

The icons at the bottom of the page are not properly aligned

I am having trouble aligning my footer icons, specifically the first 2 images. While the bootstrap icons are centered correctly, the first 2 images are not aligning as expected. I have tried various methods like align-items-center, justify-content-center, ...

Having trouble with aligning items in the center using Bootstrap 5?

Can anyone help me figure out how to center a div or img element vertically within another div element? I've tried using align-items-center", but nothing seems to be working. I've also experimented with changing the display properties of both ele ...

Tips for adjusting the search bar's position on a mobile device when it is activated by the user

I need help with an open source project where I am developing a search engine using Angular. When using smaller screen sizes, the search bar is positioned in the middle but gets hidden behind the keyboard terminal when clicked on. Can anyone advise on ho ...

I possess a certain input and am seeking a new and distinct output

I am looking to insert a word into an <input> and see an altered output. For example, Input = Michael Output = From Michael Jordan function modifyOutput() { var inputWord = document.getElementById("inputField").value; var outputText = "print ...

Using Selenium to choose an element based on the text of its sibling element

I've been working on a selenium script for: My goal is to select the "Add to Compare" element for "Sony Xperia," but it's not being located. I've tried using both cssSelector and xpath, but I can't seem to figure out what I'm doin ...

Position the image on the right side of several lines of text

My webpage contains two div elements: one for displaying multi-line text and the other for showing an image which is positioned to the right of the text. The width of the image is not fixed and can be adjusted using a user-defined parameter. <div> ...

What strategies can be implemented to decrease the initial loading duration of a YouTube iframe video?

What are some techniques we can use to decrease iframe loading time? Is it possible to implement lazy loading for YouTube iframe videos? I experimented with initially hiding the iframe and displaying an image instead. However, when the user clicks, it req ...

Troubleshooting HTML Output Display Issues

I've been trying to post my content exactly as I submit it, but for some reason, it's not working. When I enter two paragraphs in a post, the output doesn't maintain that formatting. Instead, it removes the paragraph breaks and displays the ...

Collapsed navbars in Bootstrap 5 fail to display properly in a two-column format

Looking to create a responsive Bootstrap 5 navbar that collapses at the md breakpoint and displays navlinks in two columns upon collapse. Currently facing an issue where the navbar remains expanded and the toggle button fails to work after hitting the br ...

A guide on using jQuery to iterate through 3 separate div elements

Seeking assistance with creating a dynamic loop for multiple divs (3 or more) using jQuery. The desired outcome is to have the main image div on the homepage rotate with other divs, changing both the background image and links within each div. I initially ...