Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Having Troubles with flexbox

Hey Everyone,

I have been trying to practice flexbox but I seem to be missing something and getting weird behavior from some of the items on my page. I'm going to try and include the link to my workspace and to the site itself.

Ideally the two columns should be side by side and I can't figure out why the cemetery is taking up so much space.

UPDATED: Workspace Snapshot: https://w.trhou.se/b1t3u4beeb

Thank you for any help.

Just note that it isn't possible to just make a link to your workspace. If you just provide the link, I still won't be able to see it.

To post snapshots, please watch this video. :smile:

Once you provide the link to the snapshot, I can check out your workspace and help you figure out what's wrong :thumbsup:

Thanks for understanding! ~Alex

4 Answers

I made this for you real quick. How to create columns visual reference attached. Copy and paste to your editor and you can see exactly how the code creates the layout. HTML and CSS provided.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flex-box columns tutorial</title>
    <link rel="stylesheet" href="student.css"> 
</head>
    <body>
        <div class="parent1">
            <div class="column1">
                <div>box 1</div>
                <div>box 2</div>
                <div>box 3</div>
                <div>box 4</div>
            </div>
            <div class="column2">
                <div>box a</div>
                <div>box b</div>
                <div>box c</div>
                <div>box d</div>
            </div>
        </div>
    </body>
</html>
.parent1 {
    width: 80%;
    display: flex;
    display: -ms-flex;
    display: -moz-flex;
    display: -webkit-box;
    display: -webkit-flex;
    flex-flow: row nowrap;
    justify-content: space-around;
    align-items: center;
    margin: auto;
}
.column1,
.column2 {
    display: flex;
    display: -ms-flex;
    display: -moz-flex;
    display: -webkit-box;
    display: -webkit-flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
}

.column1 div,
.column2 div {
    width: 400px;
    height: 300px;
    background-color: #22d6d3;
    border: 1px solid #000;
    margin: 10px auto;
}

I realized while I was making my breakfast that I put row nowrap on the parent element. It should wrap. That will take the letter boxes and place them below the number boxes when the viewport is resized. No media query necessary. Also, you probably want the margins on the image to be margin: 10px 10px; This will keep them from touching in the center when the viewport is resized. It essentially makes the breakpoint 40px sooner, but will avoid uneven whitespace around "adjoining" images. I hope this all helps! - if you need help understanding any of it, after checking it out in your editor, I will be happy to break it down for you. Have a good one. ~Kyle

Hello Alexander,

Thanks for the heads up! Here is the new link from the video:

https://w.trhou.se/b1t3u4beeb

Also, Thank you for any help you can provide.

Thank you so much Kyle for your response. This definitely helps out. Though I am unfamiliar with : display: -ms-flex; display: -moz-flex; display: -webkit-box; display: -webkit-flex; What is the purpose of this part of the code?

Not a problem at all. The seemingly endless display prefixes are for browser compatibility. Each one specifies a different browser - like safari or chrome.. FYI keep in mind as you learn, flex-box is not the only property-value pair that requires a prefix to work.

Awesome, Thanks for the heads up Kyle!