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

Hunter Hawley
Hunter Hawley
3,948 Points

Equal Length Columns

I need one column to be equal length as the sidebar, but can't figure out how to do it with CSS?

Anybody know?

2 Answers

Hi, Hunter Hawley:

There's a variety of ways to do this.

*Edit: Thought you meant equal height originally for some reason. :) *

Equal Width

Use border-box and you can use either similar equal width via relative or absolute values

You also have flexbox at your disposal, using flex-grow to ensure congruency between the sidebar and other element.

Like what Tony Li mentioned, you can use a grid system, but it's probably overkill if you simply want to guaranteed equal width between the two.

The exception of course is a Sass grid system that'll allow you to import the relevant space-related mixins you need without the need to explicitly associate certain css classes to make the sidebar and another element the same size.

One that would be of great use of you is the ratio-based Sass grid system called Singularitygs.

Equal Height

One classic way is to fake it through a background image. Another way is to use height: 100% for elements contained within the same parent container with some caveats involved. Fortunately, Guil Hernandez recently released a class that goes into details about this technique (being another classic technique).

Another way is to use Flexbox which automatically forces all elements within a flex container to stretch by default. Again, this is covered by Guil Hernandez in his CSS3 Foundations class. The cons of this technique is browser support, Flexbox isn't well-supported by a variety of browsers that may be relevant for you to accommodate for the project you're working on.

Tony Li
Tony Li
976 Points

Hi Hunter Hawley have you apply a grid system or not? Just set the max-width 100% and assign sidebar and your column into same grid number, you will get it. here are some good grid system i used before: @bootstrap, @gumby, @fluidable