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

Setting element to fixed position breaks its width out of container

I am setting my .buttons div to fixed, but now its (100%) width does not match the containers. Any ideas how to fix this?

Here's the image of the site: http://imgur.com/ppcinkk

The HTML

<div id="create-advert" class="container">
        <form id="create-advert-form" action="" method="POST">

            <div class="buttons">
                <button id="next-button" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button">Continue</button>
            </div>
        </form>
    </div>

The CSS

.buttons{
  position: fixed;
  bottom: 0px;
  width: 100%;
}

.mdl-button {
        width: 100%;
        height: 40px;
        margin: 20px 15px 20px 0;
}

Thanks to anyone that helps!

1 Answer

Steven Parker
Steven Parker
215,939 Points

Are you sure you want to use fixed position on these items? Fixed elements are not part of the normal document flow, and are positioned relative to the window, not to their containers.

Maybe you want to use fixed position on the containers instead?

Yes, There are other components in the page and form.