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

Design

Wade Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Wade Thomas
Full Stack JavaScript Techdegree Student 9,495 Points

Responsive design

For a more complex website do you have to write a separate index.html file for each resolution, since somethings will be left out on the smart phone site that will appear on the desktop version. Could you show the best way to go about this.

4 Answers

Atanas Sqnkov
Atanas Sqnkov
14,981 Points

Hello Wade!

Wha you want to achieve can be done with media queries.

Media queries are most simply put - a css stylesheet within your css stylesheet :) They are telling the browser how to style your website at a certain device display width;

A media query looks something like this:

div.box {
        width: 200px;
        height: 200px;
        background-color: red
}

@media screen and (max-width: 340px) {
        div.box {
                display:none;
        }
}

In the sample above we have a div with a class="box" , which by default has a width and height of 200px with a red background. What the media query does is, it is telling to the browser - when the browser width gets below 340px, apply a "display: none" to the div with the class of "box". The display: none; property removes the object from the document flow.

It is considered a best practice to place your @media queries at the bottom of your *.css file, after all of your styles.

I hope I made some clarification! Cheers!

Wade Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Wade Thomas
Full Stack JavaScript Techdegree Student 9,495 Points

Wow that's what I was wondering about. Thanks much I'm going to examine this code more closely. and use it for my current project.

Dai Phong
Dai Phong
20,395 Points

No, it's not the best practice, you can you CSS Media Query to archive the best responsive web design

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Wade;

Many of the Treehouse courses cover, or at least touch on, responsive web design. There is an intermediate level CSS course titled, appropriately enough Build a Responsive Website that covers many of the aspects of taking a site to a responsive one.

Best of luck, Ken