Is there a way to reduce the spacing between these child containers when they wrap?

I'm looking to reduce the space between my child divs when they wrap

It seems like the issue lies within the media query

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 10px;
  width: 100%;
}

html,
body {
  margin: 0;
  height: 100%;
  width: 100%;
  /* added line above, remove if errors */
}

.container-2 {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background-color: red;
  align-items: center;
}

.item {
  margin: 2% 1%;
  width: 95%;
  height: 12%;
  background-color: yellow;
  border: solid black;
  border-radius: 1% 1%;
}


/* Extra large devices (large laptops and desktops, 1200px and up) */

@media only screen and (min-width: 1200px) {
  .container-1 img {
    width: 50%;
    height: 100%;
  }
  .container-2 {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .item {
    margin: 2% 1%;
    width: 25%;
    height: 12%;
    background-color: yellow;
    border: solid black;
    border-radius: 1% 1%;
  }
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="./css/menu.css">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Menu | Andy's House</title>
</head>

<body>


  <div class="container-2">

    <div class="item">

    </div>
    <div class="item">

    </div>
    <div class="item">

    </div>
    <div class="item">

    </div>
    <div class="item">

    </div>
    <div class="item">

    </div>
    <div class="item">

    </div>




  </div>


  </div>

</body>

</html>

I need assistance in minimizing the space between the divs. Any advice or help is greatly appreciated! P.S: I am new at this, so apologies for any confusion :(

Answer №1

The issue was not related to the media query. To fix it, I adjusted the container height to be set to auto like so:

.container-2 {
    display: flex;
    flex-direction: column;
    
    width: 100%;
    height: auto;
    background-color: red;
    align-items: center;
}

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

utilizing a returned list from a controller in an ajax request

When using an ajax call to store data in a database and the controller returns a list of commentObjects, how can this list be accessed in a JSP file? function StoreCommentAndRefreshCommentList(e) { var commentData = document.getElementById(ActualComme ...

Issue with Element's Response to JQuery Click Event

After pulling elements from the database in PHP, I utilized Jquery to add Elements to the page. Each button has two classes; one for controlling the GUI and another for handling the click event of that specific button. Here is the code snippet: echo " ...

Partially filling circles for a personalized coin-slider experience

Looking to create a unique coin-slider that changes the filled factor of a coin as it moves through a specific range of images. For example, when scrolling through 10 images, the filled part of the coin would transition from 0 to 1 depending on which image ...

Ways to conceal a child div element without using any specific ID reference

I encountered an issue where I need to conceal all divs within a parent div except the first one. The challenge is that these divs do not possess any unique identifiers. Is there a way to achieve this task using CSS or pure JavaScript? <div role="list ...

"activeStyle" attribute consistently being implemented on links within pagesindex.js

Just starting out with Gatsby/React and web development in general, so apologies if this is an easy fix. I'm facing an issue that I can't seem to solve. Currently, I'm working on my website's header and trying to create links to naviga ...

Ways to eliminate the white background placed behind the arrow on my bootstrap carousel

I've been attempting to create a video carousel using Bootstrap 5, and one issue I'm encountering is the appearance of a white background when hovering over the arrow. Normally, it shouldn't display a background, but for some reason, it does ...

Moving a file from one webpage to another

My current project involves creating a multi-page form consisting of 3 pages. The first page will collect user input, including an uploaded file. The second page will display a summary of the entered data for confirmation. The third page will handle submit ...

Label positioning for checkboxes

Is there a way to display the checkbox label before the actual checkbox without using the "for" attribute in the label tag? I need to maintain the specific combination of the checkbox and label elements and cannot use nested labels or place other HTML elem ...

Having trouble with my Javascript code - my HTML page is refusing to load and the innerHTML

Below is my code in the HTML file. I have implemented a flatpickr date picker to allow users to select a date. On closing the calendar, I intend to update the current document by adding some HTML content. However, this functionality does not seem to be wor ...

Is it possible to designate a specific position for absolutely positioned elements within a webpage?

Is it possible to specify a reference element for an absolutely positioned element in addition to its closest positioned ancestor? I am curious if there are any CSS or jQuery methods that allow for this customization. ...

Discrepancy in CSS rendering in Chrome and Firefox

When viewing in Chrome, the stats display properly within the gray box at the bottom left corner. However, when using Firefox, the stats appear positioned much lower below the box, with the bottom half of them hidden from view. Here is my CSS code being ...

Both the maxlenght and ng-maxlength directives appear to be ineffective in AngularJS

In my HTML file, I have the following input: <input name="password" id="newPasswordConfirmation" ng-model="newPasswordConfirmation" type="number" inputmode="numeric" placeholder="" required ...

Changing the text link color on IOS can be achieved by modifying the CSS properties

Recently, I encountered an issue with the text link color of my website. While I had set the link color to red for desktop view, it inexplicably changed to blue when viewed on an iPhone. Even after trying to use !important, the problem persisted. Can som ...

What is the best way to ensure bootstrap cards' container expands horizontally?

Currently experimenting with Bootstrap 4 cards (view more at ) My goal is to have a container with a card deck inside that stretches horizontally as I add new cards, causing a horizontal scrollbar to appear when needed. By default, when the container wid ...

Apply a unique CSS class to the first two elements, then skip the following two elements, and continue this pattern using ngFor in Angular and flex styling

Here is a code snippet that displays a list of products using *ngFor in Angular: <div class="container-products"> <div class="item-product" *ngFor="let product of ['product A', 'product B', 'prod ...

Creating HTML code from a multidimensional array is a useful skill to

I am looking to use PHP to generate HTML code similar to the following: <li id="821">Accessories for tablets and cell phones <ul> <li id="426">Cell Phone Accessories <ul> <li id="675">Stands and Docks</ ...

Guide to configuring an x-axis scroll bar for a handsontable

Utilizing the JarvisWidget library to create widgets, I encountered an issue with a table exceeding the width of the widget when using the handsontable library. I attempted to add a scrollbar by setting the CSS width to 100% and adding overflow-x:scroll, b ...

What is the process for populating a checkbox with data from a configuration file using JavaScript?

I have a requirement where I need to populate a list of checkboxes with data from a configuration file. To elaborate, if my checkboxes are meant to select sports, within my JSON configuration file I have an array like this: sports: ["Tennis", "Rugby", "S ...

Namespace SyndicationElementExtension refers to

I'm trying to achieve the following output: <someNSalias:full-text>Good news everyone!</someNSalias:full-text> This is the code I have written: var element = new SyndicationElementExtension(field.Name, field.HasNamespace ? RssNs : strin ...

experiencing a problem when trying to retrieve data from form radio buttons

I've encountered an issue with receiving form data in PHP when dealing with radio buttons created using jQuery. While all input data is received correctly for multiple fields, only the response from the first field's radio button is accurate. For ...