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 CSS Flexbox Layout Building a Layout with Flexbox Aligning Items to the Bottom of a Column

Samuel Kleos
seal-mask
.a{fill-rule:evenodd;}techdegree
Samuel Kleos
Front End Web Development Techdegree Student 13,307 Points

Why does the button stretch past the content width without specifying any width properties?

The buttons stretch their content width to fit the .col div.

However when the align-self: flex-start; rule is applied to .button the button shrinks the size of the content width to the length of the text.

@media screen and (min-width: 769px) {

        .main-header,
        .main-nav,
        .row,
        .col {
            display: flex;
        }

    .main-header {
    flex-direction: column;
    align-items: center;
    }

    .col {
        flex: 1;
        flex-direction: column;
    }
    .button {
        margin-top: auto;
        align-self: flex-start;
    }
}

1 Answer

Steven Parker
Steven Parker
231,269 Points

The default value of align-self is auto, which causes the item to stretch to fill the available space.

For more details, see the MDN page on align-self.