Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I need some help with CSS and HTML. Specifically, I want the first 5 items in my flexbox (flex-items) to occupy the entire screen, but I want the 6th item to be hidden initially and revealed only when scrolling horizontally. I've been researching extensively, but I haven't found a solution. If anyone knows how to do this, I'd greatly appreciate it. Thank you in advance :)

What I have tried:

CSS
body{
       margin: 0;
   }
   .main {
       background-color: rgb(113, 174, 174);
       width: 100%;
       height: 100vh;
       display: flex;
       justify-content: center;
       align-items: center;
   }


   .card {
       min-width: 200px;
       height: 90vh;
       background-color: white;
       display: flex;
       gap: 2vw;
       padding: 2vw;
       overflow-x: auto;
   }
   .coluna {
       border-radius: 20px;
   }
   .coluna {
       flex-grow: 1;
   }
   #col-1 {
       background-color: rgb(252,229,229);
       width: 100vw;
   }
   #col-2 {
       background-color: rgb(229,245,255);
       width: 100vw;
   }
   #col-3 {
       background-color: rgb(244,237,254);
       width: 100vw;
   }
   #col-4 {
       background-color: rgb(244,237,254);
       width: 100vw;
   }
   #col-5 {
       background-color: rgb(244,237,254);
       width: 100vw;
   }
   #col-6 {
       background-color: rgb(228,230,239);
       width: 500px;
   }

HTML
<pre> <!DOCTYPE html>
    <html lang="pt">

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

    <body id="tag">
        <main class="main">
            <div class="card">
                <div class="coluna" id="col-1">
                </div>
                <div class="coluna" id="col-2">
                </div>
                <div class="coluna" id="col-3">
                </div>
                <div class="coluna" id="col-4">
                </div>
                <div class="coluna" id="col-5">
                </div>
                <div class="coluna" id="col-6">
                </div>
            </div>
        </main>

    </body>

    </html>
Posted
Updated 7-Dec-23 3:55am
v2

1 solution

It's not entirely clear what you're trying to do.

Do you want each of the first five items to fill the width of the screen?
CSS
body {
    margin: 0;
}

.main {
    background-color: rgb(113, 174, 174);
    width: calc(494vw + 500px);
    height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.card {
    min-width: 200px;
    height: 90vh;
    background-color: white;
    display: flex;
    gap: 2vw;
    padding: 2vw;
}

.coluna {
    border-radius: 20px;
	width: 96vw;
}

#col-1 {
    background-color: rgb(252, 229, 229);
}

#col-2 {
    background-color: rgb(229, 245, 255);
}

#col-3 {
    background-color: rgb(244, 237, 254);
}

#col-4 {
    background-color: rgb(244, 237, 254);
}

#col-5 {
    background-color: rgb(244, 237, 254);
}

#col-6 {
    background-color: rgb(228, 230, 239);
    width: 500px;
}
Demo[^]

Or do you want the first five items to appear at once, and the sixth to be pushed off the edge of the screen?
CSS
body {
    margin: 0;
}

.main {
    background-color: rgb(113, 174, 174);
    width: calc(102vw + 500px);
    height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.card {
    min-width: 200px;
    height: 90vh;
    background-color: white;
    display: flex;
    gap: 2vw;
    padding: 2vw;
}

.coluna {
    border-radius: 20px;
	width: calc(calc(100vw - 12vw) / 5);
}

#col-1 {
    background-color: rgb(252, 229, 229);
}

#col-2 {
    background-color: rgb(229, 245, 255);
}

#col-3 {
    background-color: rgb(244, 237, 254);
}

#col-4 {
    background-color: rgb(244, 237, 254);
}

#col-5 {
    background-color: rgb(244, 237, 254);
}

#col-6 {
    background-color: rgb(228, 230, 239);
    width: 500px;
}
Demo[^]
 
Share this answer
 
Comments
José Henrique Queiroz 7-Dec-23 11:19am    
Thank you so much the seccond solution worked for me, first five items to appear at once, and the sixth to be pushed off the edge of the screen. You're goat.
Andre Oosthuizen 7-Dec-23 13:52pm    
+5'ed, Well done you "goat"
Maciej Los 8-Dec-23 5:32am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900