Unexpected malfunction in CSS Grid within Flexbox layout

After extensive testing, I have found that the .articleWrapper for post child items scales correctly when used on its own. However, as soon as I place this .articleWrapper inside another wrapper-element with display: flex, it loses its ability to scale horizontally after reaching a certain point.

I suspect there is a flaw in my logic somewhere, but I just can't seem to pinpoint it.

Here is the code snippet that illustrates the issue. When I remove display: flex and flex-wrap: wrap;, the grid functions perfectly. Similarly, replacing flex with block also works fine. But adding back in display: flex; causes the grid content to no longer stack as desired.

.siteWrapper {
    display: flex;
    flex-wrap: wrap;
}

.articleWrapper {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    grid-template-rows: repeat(auto-fit, minmax(285px, 1fr));
    max-width: 1100px;
    margin: auto;
}

article {
    background-color: red;
}
<head>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="siteWrapper">
    <div class="articleWrapper">
        <article>
           <h1>Title</h1>
           <p>Para</p>
        </article>
        <article>
            <h1>Title</h1>
            <p>Para</p>
         </article>
    </div>
</div>
</body>

Answer №1

After some trial and error, I managed to stumble upon a solution that resolved the problem at hand. However, the logic behind why it works still eludes me. By including width: 100%; in the .articleWrapper class, the issue appears to have been rectified in this particular instance.

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 is causing the data element to remain unchanged within a Vue.js function and what steps can be taken to ensure its value can be updated?

Using the axios API in the created() function, I am able to access webURLs. When a mouseover event triggers a v-for handler in the HTML file, the index is obtained and assigned to the selectedState data element. Although the value of selectedState changes ...

Two columns of equal height featuring three card UI elements

I'm currently working with Bootstrap 4 and I have a grid set up with 1 row containing 2 columns and 3 card elements. However, I am struggling to adjust the height of the blue card element to align with the yellow card element. I want both cards to ha ...

Troubleshooting problem with presenting real-time data in a Bootstrap Carousel using PHP

Currently, I am in the process of developing a dynamic events calendar to showcase on a website homepage. The information displayed on this calendar is retrieved from a database using PHP. Additionally, I have implemented the Bootstrap framework (version 4 ...

The Bootstrap navigation bar is not functioning as expected

After building a landing page with a bootstrap navbar, I noticed that the hamburger menu doesn't display the list of items when the screen size is decreased. Here is the code I used: <nav class="navbar navbar-expand-lg" id="navbar&qu ...

What is the best way to display multiple HTML files using React?

Looking to develop a web application using React that consists of multiple HTML pages. For instance, login.html and index.html have been created and linked to URIs through the backend - resulting in localhost:8080/login and localhost:8080/index. However, R ...

Selenium allows the liberation of a webpage from suspension

I'm facing an issue with resolving the suspension of a website as shown in the image below. My goal is to access a ticket selling website every 0.1 seconds, but if it's busy, I want it to wait for 10 seconds before trying again. Visit http://bu ...

css absolute positioning and setting the height of a repeating background

I am facing a challenge with a container that contains a repeating image and I want it to fill 100% of the available height. However, some inner divs have their :after pseudo elements absolutely positioned to achieve the desired borders, which is causing a ...

How can I retrieve the current page URL with Thymeleaf?

Trying to highlight the current element in the menu using Bootstrap and the "active" class, but unsure how to retrieve the value of the current page. Below is my navigation bar: <nav class="navbar navbar-expand-md sticky-top navbar-light bg-faded"> ...

Clicking randomly on the page to conduct test trials

Currently, I am seeking a way to ensure that my web page is flawless, specifically in terms of broken paths. Given that my website will utilize a touch screen interface, it is crucial to test the entire page thoroughly. While I have limited experience in a ...

Transforming an image into a geometric shape using html and css - step by step guide

Hey fellow stackoverflow users! I've created a geometric figure using multiple divs for an unconventional website design. However, I'm struggling to adapt images within these divs because the original width is not being maintained. When you view ...

Selenium was unable to find the p tag element on the webpage

I apologize for reaching out to you all for assistance with such a basic task, but I have tried everything in my toolkit and still can't seem to figure it out. I've experimented with partial xpath, full xpath, and various CSS selectors. I am see ...

Steps for including an animation class in a div

Is it possible to add the sweep to top blue color animation to the red box using a set-timeout function instead of hover? I tried using the following code but it doesn't seem to be working. Can you help me troubleshoot? setTimeout(function() { $( ...

"Utilizing SVG format to manipulate text, adjusting font size within tspan elements

There seems to be an issue with the font size on SVG. Even though both the SVG and paragraph have a font-size of 16px, they appear different. I would like the font size in the SVG to match that of the paragraph. Another concern is how to center <tspan ...

PHP query string parameter

Within the index.php file, I am looking to add a language selection option. Here is the code snippet I have: <?php if( isset( $_GET['target'] ) ) $target = $_GET['target']; else $target = "productie"; if ( isset( ...

Discover the steps to trigger a Bootstrap popup modal when clicking on an anchor link using Angular

I have an Angular application and I would like to display a Bootstrap popup modal when the user clicks on a link in the footer. Here is the Bootstrap modal code: <button type="button" class="btn btn-primary" data-toggle="modal&q ...

What is the correct method in CSS to resize an image while maintaining its proportions within a div container?

I've been struggling to properly insert images into a <div> element on my website. I've experimented with various techniques, such as setting max-width and max-height to 100%, changing the display property of the parent element to flex, and ...

Bootstrap 4 collapsible navbar with a stacked design

I am struggling to create a collapsible navbar. Even though everything seems to be working, the nav items are not stacking vertically as they should be. Instead, they are appearing horizontally next to each other. Here is the code snippet: <nav class= ...

Aligning a picture with a heading

I'm currently working on a website header design where I am struggling to align the logo and site title horizontally. As someone who is new to CSS, any guidance or tips would be greatly appreciated! The logo image has the following styling: .logo { ...

What steps can I take to ensure that an image does not exceed the size of its parent tag?

Is there a way to ensure that items placed in a container do not exceed the boundaries of the container? I am trying to use my logo as the home button, but when I set the image height and width to 100%, it becomes larger than the nav bar. The CSS for the n ...

Enable the ability to upload multiple images on a single page using droparea.js

I am currently utilizing droparea js for uploading images. However, I have encountered an issue where if I try to upload an image in one of the upload menus, it ends up changing all four upload menus simultaneously. <div class="col-md-12"> ...