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 trialTobi Ogunnaike
2,242 Points#BeginnerBlues Portfolio is not changing back to 2 column layout when scaled down for mobile view. Please help!
My portfolio was previously a 2 column layout but I have added an image query to try to make it responsive i.e. 3 column layout for larger view media (laptops etc).
But for some reason, when I scale my browser down to imitate the mobile view, my portfolio still has a 3 column layout.
My site is available here: http://port-80-bz2gnxtxrh.treehouse-app.com/index.html
BeginnerBlues
Any ideas? Thanks!
Tobi Ogunnaike
2,242 PointsCan you access it now?
So in main.css, I wrote this to make it a 2 column layout
#gallery li{
float:left;
width:45%;
margin:2.5%;
background-color:#f5f5f5;
color:#bdc3c7;
}
And in responsive.css, I wrote this to try to make it a 3 column layout:
#gallery li{
width:28.3333%;}
Is it because the responsive.css comes after main.css, that I'm having the 3 column layout even at the mobile view?
Thanks!
Raymond Wach
7,961 PointsYes, I was able to check out your site now.
3 Answers
Raymond Wach
7,961 PointsSo I don't see anything in the code you have posted that would prevent one #gallery li
selector from override the other every time. By that I mean, that since the two selectors are exactly the same, which ever selector appears later in the source code with override the previous value. You can see which rules are being applied and overwritten by inspecting one of the list items on the site.
Remember, you need to use a media query to conditionally apply a new CSS rule. If you have a query, post it here and we can try to figure out what's going on (or not going on) to prevent the site from switching back and forth. The likely issue is that the conditions you are using for the media query are not exclusive enough so that you are ending up with only one rule ever being applied (just as if you weren't using a query at all).
I came across this blog post that gives some good examples of media query conditions and explains the semantics of min-width
and max-width
in conditions.
Update
Now that you've posted your code, what's happening is that the rule setting the three column layout is overriding the two-column layout in every case because it occurs later in the source file. However, I think that you also need to change your media query conditions. From what I understand of the Mobile First methodology, you should define the two column layout as the default, unconditional, style and use a media query to conditionally apply the three column layout when the screen is sufficiently large.
Raymond Wach
7,961 PointsFor the record, I haven't read the scotch.io post that I linked here; I just did a search for "media query mobile screen max-width" looking for some typical screen sizes. This was one of the first results that came up and looks like it sets some good reference values with good explanations for them. That said, it looks like a good resource.
Tobi Ogunnaike
2,242 PointsThanks. I will check those posts out!
@media screen and (min-width:480px){
/**********************************
TWO COLUMN LAYOUT for Contact page
**********************************/
#primary{
width:50%;
float:left;
}
#secondary{
width:40%;
float:right;
}
}
/******************************************
PAGE:PORTFOLIO (This makes 3 photos per row)
*******************************************/
#gallery li{
width:28.3333%;}
#gallery li:nth-child(4n){
clear: left
}
/****************************
PAGE: ABOUT
*****************************/
.profile-photo{
float:left;
margin:0 5% 80px 0;
}
That's the first media query with the associated code.
Below is the second media query:
@media screen and (min-width:660px){
/**********************************
HEADER
**********************************/
nav{
background:none;
float:right;
font-size:1.125em;
margin-right:5%;
margin-top:120px;
text-align:right;
width:45%;
}
#logo{
float:left;
margin-left:5%;
text-align:left;
width:45%
}
h1{
font-size:2.0em;
}
h2{
font-size:1em;
margin-bottom:20px;
}
header{
border-bottom:5px solid #d77000;
margin-bottom:60px;
}
}
Could it be something incorrectly selected in the main.css document that precedes this code?
Thanks for the help!
Raymond Wach
7,961 PointsTobi Ogunnaike, thanks for sharing your code. I think I know what's going on and I updated my answer to include my new thoughts.
Tobi Ogunnaike
2,242 PointsThat's interesting because our teacher taught us to design first with the mobile first approach (like you said) yet he set two media queries (one at 480px for mobile devices and the other at 660px for larger screens)
However, his code works and mine doesn't.
How would you go about defining the 2 column layout as the default, unconditional style?
If you view my about page in a mobile view, the the text is to the right of the image i.e. 2 column view instead of a single column view. Any tips on sorting that out? Thanks
Raymond Wach
7,961 PointsOh that's right (it's been a little while since I watched the video), so what they do that case is to have the mobile view (the two column layout) applied in the most general media query and then use more limited conditions to override the mobile view with styles for larger screens.
What I was suggesting (which is may be a misunderstanding of Mobile First on my part) would be to specify the two column layout outside of any media query with the intention of overriding it with subsequent media query rules that apply to non-mobile views.
The other problem you mention with the About page is something that I struggle with, as well. My suggestion would be to inspect the paragraph and check your CSS to see if the styles you think should be applied are actually taking effect. Just scanning your CSS, I didn't see anything that would be relevant, but I might have missed something. I want to ask, "why do you think the text shouldn't be to the right of the image?", but that comes across more hostile that I mean. What I'm looking for is what rules you think should apply to the elements on that page because apparently your browser disagrees with you so we need to figure out why that is.
Tobi Ogunnaike
2,242 PointsI see what you mean by "why do you think the text shouldn't be to the right of the image?" and my honest answer is "I don't know". Looking over my code, I can't find any line that tells the browser to create a single column. However, I found a forum on this issue which solved my 2nd problem with this code.
profile-photo {
display: block;
width: 80%
margin: 0 5% 80px 0;
With regards to Mobile First, I see your point. I think both approaches could work as long as the ranges are specified correctly.. If I delete all the code in my responsive.css file, my portfolio returns to a 2 column display (proving that the mobile first approach works). Hence, the problem must be in the responsive.css file. This code is the problem:
/******************************************
PAGE:PORTFOLIO (This makes 3 photos per row i.e. 3 column layout
*******************************************/
#gallery li{
width:28.3333%;}
#gallery li:nth-child(4n){
clear: left
}
Can you suggest an alteration?
Raymond Wach
7,961 PointsI would put the three column layout code inside a media query with a condition that a small screen can't satisfy such as min-width: 1024px;
. After all, you aren't necessarily trying to rule out a three column layout on small screens, you're trying to balance two presentational styles to get the best appearance in a smaller screen and avoid wasted space in a larger screen.
With regards to your other problem, I would be interested in a link to the post that helped you or if you could explain how that code solves the problem you were having. This touches a part of CSS that I have a hard time understanding so I am really asking for my benefit.
Tobi Ogunnaike
2,242 PointsI've fixed it! It was a syntax issue, found an extra bracket and got rid of it. I would try your idea though.
Sure, here's the link https://teamtreehouse.com/forum/resizing-the-page-doesnt-change-2-column-layout-to-1-column
Thanks for the help!!
Raymond Wach
7,961 PointsRaymond Wach
7,961 PointsIt doesn't look like I can access your site at the moment. Could you post the CSS that should be scaling the view and the CSS that should generate the two column layout in your question? Also, if you wrap it in triple backticks (`) then the forum will style it as code:
```CSS
background: #f90;
}
```
is displayed as