Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 3,703 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
218,596 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.