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 Build a Responsive Website Adaptive Design Implementing Media Queries

Alexis Grizos
Alexis Grizos
3,907 Points

Using media queries

I have added the @media.... for the 480px and in my example (smells like bakin) i do not get to see the one column transformation of the photos (one by one) in the video every single picture of the website when the video ends is exactly under the previous one as if there are aligned on the left. Am i missing something in my example? I hit the code playground and i saw another js file, which is not introduced so far in the video sessions, does that have something to do with the image transformation?

4 Answers

Neill dev
PLUS
Neill dev
Courses Plus Student 23,163 Points

Hi Alexis, You probably need to add a bit more detail to this post if this is the wrong answer, example of your code so far e.t.c. but I think you are referring to the grid.

Its not just the images that appear aligned to the left, it should be all the divs, elements e.t.c. This is achieved by adding below to your media query.

In essence below tells the browser that at a max-width of 650px all elements given a grid class span 100% of the viewport size. As divs, imgs e.t.c. are block level elements they will all appear beneath each other, you could for instance change which appear first, second, third in the browser by cutting and pasting the img code and replace them with each other within the HTML class. Rewatch the adaptive design video and check the grid section.

@media screen and (max-width: 650px) {

    .grid_1,
    .grid_2,
    .grid_3,
    .grid_4,
    .grid_5,
    .grid_6,
    .grid_7,
    .grid_8,
    .grid_9,
    .grid_10,
    .grid_11,
    .grid_12    {
        width: 100%;
    }

No Javascript required for this, I think the js file you saw is used for the picturefill section. That is where certain large or retina screen comptible images are swapped out for smaller sized ones depending on the viewport size (device) to enable faster downloads over 3G e.t.c.for phones/tablets.

Hope that helps,

Rgds Neill

Alexis Grizos
Alexis Grizos
3,907 Points

Hey Neill thnx for the answer. My code is exactly like the screenshot you are presenting.

@media screen and (max-width: 480px){ .grid_1, .grid_2, .grid_3, .grid_4, .grid_5, .grid_6, .grid_7, .grid_8, .grid_9, .grid_10, .grid_11, .grid_12 { max-width: 480px; }

}

Is there anything else i should add on my code? Maybe something that is not presented in this video?

Neill dev
PLUS
Neill dev
Courses Plus Student 23,163 Points

Hi Alexis, Well you should be using a % size for the grid width at the bottom of that code, ..grid_12 max-width: 100% not ..grid_12 max-width: 480px; The % is what gives the elements the ability to respond relative to the browser/veiwport size.

However, you should still be seeing the expected result when resizing your browser to 480px from what I can see there.

Try it with the 100% max width, if no joy then the error is elsewhere in your code. I would suggest re watching the video's and if its still not making sense upload some more css/html code snippets for us to check out.

When watching the videos make sure you understand the use of the grid and are naming your HTML elements correctly to correspond with the grid and css e.t.c.

Rgds Neill

Alexis Grizos
Alexis Grizos
3,907 Points

Hello Neill, i tried this (%) but it seems that something else is wrong, so far everything looked to be working properly, in any case i will watch the video again to see if i am missing something!!