Troubleshooting a Flexbox flex-direction problem

Looking for some help with flexbox! I have a container with 2 blocks inside. My goal is to change the flex-direction to "column" when the screen width is less than 700px, but I'm having trouble getting it to work. Currently, when the screen width is less than 700px, neither block is displaying. :)

Here's my code in index.html:

<html>
<head>
    <title>Flexbox</title>
 </head>
<body>
        <div class = "container">

            <div class = "slot_1"></div>
            <div class = "slot_2"></div>

        </div>

 <style>
  *{
    margin: 0 auto;
    padding: 0 ;
}
.container{
    width:100%;
    height:100%;
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;

}
 .slot_1{
     background:red;
      flex: 3;
}

.slot_2{
    background:orange;
    flex:1;
}

@media (max-width:700px){
    .content{
        flex-direction: column;
    }

}
 </style>
</body>

Hope someone can help me figure this out!

Answer №1

There are a couple of issues that need to be addressed:

  1. .content should actually be changed to .container.
  2. You need to specify the width for both .slot_1 and .slot_2.

Below is the updated CSS code:

  *{
    margin: 0 auto;
    padding: 0 ;
}
.container{
    width:100%;
    height:100%;
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;

}
 .slot_1{
   height: 30px;
     background:red;
      flex: 3;
}

.slot_2{
  height: 30px;
    background:orange;
    flex:1;
}

@media all and (max-width: 700px){
    .container{
        flex-direction: column;
    }

    .slot_1,
    .slot_2 {
      width:100%;
    }

}

I have added a 30px height for demonstration purposes.

Furthermore, here is a working example using your code: https://jsfiddle.net/x5h1ohzr/

Answer №2

The media query refers to the incorrect class name as .content. Should it actually be referring to .container instead?

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

Increase the padding on the left side of a background image

UPDATE: Solution discovered at this link thanks to Mr. Alien I am attempting to create a heading that resembles the following Title ------------------------------------------------- I have an image that I intend to use as a backdrop for it. However, I& ...

Wrapping multiple floating divs with varying dimensions inside a parent div using shrinkwrap technique

To ensure that divs of varying numbers, widths, and heights have matching heights, I am implementing a jQuery script that requires them to float. However, I prefer for them to be centered, so I am utilizing the relative position trick for centering. CSS ...

What is the reason for Bootstrap requiring both a class name and an ID name for collapse functionality?

When implementing the collapse effect in Bootstrap, why do buttons need to refer to the data-toggle=collapse class and the data-target=#collapseExample ID of the panel for the effect? Wouldn't simply targeting the ID be enough to toggle its state? Co ...

The issue with CSS3 rotate3d rotation

I'm facing an issue with the rotate3d function. Take a look at this Fiddle: https://jsfiddle.net/c3snpkpr/ The problem arises when hovering over the <div> from the left or right - sometimes it rotates properly, and other times it bugs out by r ...

I prefer to have my side navigation bar open on desktop and laptop screens, but closed on mobile devices

I am experiencing an issue with the side navigation menu. Is there a way to have the side nav instantly open on desktop, while remaining closed on mobile phones? I have tried using the "active" class but the side nav stays closed. <!DOCTYPE html> & ...

Concealing a message within a section that has been minimized to a width of 0

Recently, I've encountered a challenge in attempting to set the width of a section to 0 and have all its contents also disappear. Despite changing the section's width to 0px, the text inside continues to be displayed and even shifts off to the si ...

triangle shape filled with a gradient that transitions between two colors

I have two triangles displayed at the bottom of my page - one on the left and one on the right. The right triangle is currently transparent but I want to add a gradient effect to it. For the triangle-bottom-right, I'd like the gradient to go from rgb ...

"Creating Eye-Catching CSS Animation Effects with Dynamic Initial States

I am looking to understand how I can seamlessly transition from a hover-triggered animation to an exit-hover animation, regardless of where the hover animation is in progress. Currently, if I exit hover too quickly, the animation jumps back to its starting ...

Guide to changing the border color in a Material-UI TextField component styled with an outline design

To complete the task, utilize the Material UI outlined input field (TextField component from "@material-ui/core": "^4.12.2",) and apply a custom blue color style to it. Here is the outcome of my work: https://i.sstatic.net/lw1vC.png C ...

Is there a way to eliminate unknown white gaps in the content?

I have encountered a very perplexing issue. When accessing this site on Safari, an additional 4-500px of scrollable whitespace is added. This is clearly not the intended behavior, but I am struggling to understand what is causing this space :S Upon inspe ...

Transitioning the image from one point to another

I am currently working on a unique single-page website and I have been experimenting with creating dynamic background animations that change as the user scrolls. Imagine my website is divided into four different sections, each with its own distinct backgro ...

Create a border around the text using a strokeoutline

I'm attempting to apply an outline to text using CSS. The issue I'm facing is that the shadow doesn't work well for perfectly stroked text. Is there a way to achieve this with just CSS? Below is the code snippet I am currently using: . ...

Tips for resolving text center alignment problems along with other elements when hovering

When hovering over each ul li element, a new element is added to the right side of the text. The alignment of the text is centered by default, but upon hover, the alignment changes when the new element is added. However, the issue is that the alignment s ...

Vercel deployment is experiencing issues with the integration of Tailwind CSS

I've encountered an issue with my website where it works fine on local hosts but when deployed on Vercel, the output.css file is empty. Here is a snippet from my package.json file: { "devDependencies": { "tailwindcss": "^3.1.8" }, "scripts" ...

What is the best way to ensure a logo image is properly scaled to fit its parent container using Bootstrap 4

I am struggling with my navigation bar, which consists of a simple logo and a few links. The issue I am facing is that the logo image is too tall for the parent container, which has a fixed height. It's clear that the logo with the gray background e ...

Is there a way to dynamically change the source of an image based on different screen sizes using Tailwind CSS?

Currently, I am utilizing the next/Image component for setting an image and applying styling through tailwindcss. However, I have encountered a roadblock at this juncture. My Objective My goal is to dynamically change the src attribute of the image based ...

Placing a list item at the beginning of an unordered list in EJS with MongoDB and Node.js using Express

What I've done: I already have knowledge on how to add an LI to UL, but it always goes to the bottom. What I'm trying to achieve: Add an LI to the top so that when my div.todos-wrapper (which has y-oveflow: hidden) hides overflow, the todos you a ...

Enable automatic scrolling for CSS overflow: scroll feature

I am currently developing a chat application where messages are displayed in a background. I have used CSS to add an overflow scrollbar with the line overflow-y: scroll;. Everything is working properly, but I'm wondering if there is a way to automatic ...

Is it possible to manipulate an image tag's image using only CSS?

Is it possible to hide an image from the src attribute of an <img> tag and instead set a background image on the tag using CSS? One idea could be adjusting the positioning or text-indent of the actual image to move it out of view, and then applying ...

Troubleshooting: Unable to get the Bootstrap active navigation code to function

I've been struggling to make this code work in order to add the active class to my navigation list item, but it just won't cooperate. Home <li id="orange"> <a href="hotels.php"><span class="glyphicon glyphico ...