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 trialDan Cartwright
7,009 PointsGrid Container content problem, when changing size from full screen down to mobile device ? how to keep content together
Hi.
I am currently having the problem of a sample website I had started developing, I am adjusting the layout currently.
From the desktop/full screen view everything appears fine and in order, but as i then scale down to the tablet and mobile view the grid containers move around and change there size ? The images inside the grid containers also move around.
The final issue i have is that i have used a fixed header and navigation so the content will scrolling underneath it. But again the problem occurs when I go to mobile view and the content seems to get stuck underneath ?
If anyone could solve or give advice on this issue that would be very helpful !
Thanks
Dan
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--Title-->
<title>Chester FC | The Story So Far... </title>
<script type="text/javascript" src="jquery.js"></script>
<!--Mobile Specific Metas-->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--Stylesheet-->
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/responsive.css">
<link rel="stylesheet" href="jquery.js">
<link rel="stylesheet" href="css/gridsystem.css">
<link href='http://fonts.googleapis.com/css?family=Dosis:300,400,500,600,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Exo:400,500,700|Ropa+Sans' rel='stylesheet' type='text/css'>
<!--Page Icon-->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body>
<header>
<a href="index.html" id="logo">
<h1>Chester FC</h1>
<h2>The Story So Far . . .</h2>
</a>
<div class="grid-container">
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="seasons.html">Seasons</a>
<!-- First Tier Drop Down -->
<ul>
<li><a href="2011.html">2010/2011</a></li>
<li><a href="2012.html">2011/2012</a></li>
<li><a href="2013.html">2012/2013</a></li>
<li><a href="2014.html">2013/2014</a></li>
<li><a href="2015.html">2014/2015</a></li>
</ul>
</li>
<li><a href="theclub.html">The Club</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</div>
</div>
</header>
<div class="site">
<div id="wrapper">
<!--
<hr div class="line1"></hr>
--->
<div class="onepcssgrid-1200">
<div class="onerow">
<div class="col9"><img src="images/final.jpg"></div>
<div class="col3 last"></div>
</div>
<div class="onerow">
<div class="col4"></div>
<div class="col4"></div>
<div class="col4"></div>
</div>
<div class="onerow">
<div class="col3"></div>
<div class="col3"></div>
<div class="col3"></div>
<div class="col3"><img src="images/richards.jpg"></div>
</div>
</div>
</div>
</div>
<div class="footer">
<div style="clear: both"></div>
</div>
</body>
</html>
/* *********************************************************************************************************************
* Main container for all
*/
.onepcssgrid-1000, .onepcssgrid-1200 {
margin: 0 auto;
padding: 0 0 0 1%; /* THAT'S THE NAME ;) */
}
.onepcssgrid-1200 {
max-width: 1220px;
}
.onepcssgrid-1000 {
max-width: 1020px;
}
.onerow {
clear: both;
padding: 0 10px;
}
/* *********************************************************************************************************************
* Common columns definitions
*/
.col1, .col2, .col3, .col4, .col5, .col6, .col7, .col8, .col9, .col10, .col11, .col12 {
float: left;
margin: 0 0.5% 0 0;
}
.col1.last, .col2.last, .col3.last, .col4.last, .col5.last, .col6.last, .col7.last, .col8.last, .col9.last, .col10.last, .col11.last, .col12 {
margin: 0;
}
.col1 { width: 5.5%; }
.col2 { width: 14%; }
.col3 { width: 22.5%; }
.col4 { width: 31%; }
.col5 { width: 39.5%; }
.col6 { width: 48%; }
.col7 { width: 56.5%; }
.col8 { width: 65%; }
.col9 { width: 73.5%; }
.col10 { width: 82%; }
.col11 { width: 90.5%; }
.col12 { width: 99%; margin: 0; }
.col1 img, .col2 img, .col3 img, .col4 img, .col5 img, .col6 img, .col7 img, .col8 img, .col9 img, .col10 img, .col11 img, .col12 img {
width: 100%;
height: auto;
display: block;
}
/* Styling*/
.col4 {
background-color: #034896;
border-radius: 10px;
height: 150px;
padding: 10px 0px 10px 10px;
margin-top: 20px;
font-family: 'Dosis', sans-serif;
}
img {
-moz-border-radius:10px;
-webkit-border-radius:10px;
-o-border-radius:10px;
}
.col7 {
margin-top: 10px;
padding: 10px 0 0 0;
}
.col6 {
background-color: #034896;
border-radius: 10px;
height: 250px;
margin-top: 2px;
margin-bottom: -10px;
font-family: 'Dosis', sans-serif;
color: #fff;
}
.col3 {
background-color: #034896;
border-radius: 10px;
height: 240px;
margin-top: 5px;
margin-bottom: -25px;
padding-right: 15px;
font-family: 'Dosis', sans-serif;
color: #FFF;
}
.col9 {
background-color: #034896;
border-radius: 10px;
height: 140px;
margin-top: 1px;
font-family: 'Dosis', sans-serif;
color: #fff;
margin-bottom: -25px;
}
.col2 last {
margin-top: 10px;
}
/* *********************************************************************************************************************
* Disable padding left/right 10px if I'm 1024 or gibber - correct percentage math
*/
@media all and (min-width: 1024px) {
.onepcssgrid-1000 {
max-width: 1000px;
}
.onepcssgrid-1000 .onerow {
padding: 0;
}
}
/* *********************************************************************************************************************
* Small devices
*/
@media all and (max-width: 768px) {
.onerow {
}
.col1, .col2, .col3, .col3, .col4, .col5, .col6, .col7, .col8, .col9, .col10, .col11 {
float: none;
width: auto;
}
}
7 Answers
Craig Watson
27,930 PointsHi Dan,
Here is the link to the pen, I had taken a few things out that weren't really needed, maybe some of the code had been put in there as you were trying to figure it all out.
Now whenever you next something inside the columns be sure not to give it an explicit width or that will kill off the responsive column widths.
You will be able to declare an explicit col height and that will be ok :)
I haven't done much testing on it with content so if it gets a little sticky let me know.
Also if you want a really robust grid and layout system, I use Bootstrap, paste the below in your head section like any other style sheet, right before your style sheets.
Then you will have access to all there grid features, info here!
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
If you need any more help please dont hesitate to let me know :)
Craig
Craig Watson
27,930 PointsHi Dan,
Have you managed to get to the bottom of this yet ?
Craig :)
Dan Cartwright
7,009 PointsHi Craig, I still haven't as of yet ? I'm sure it's something simple but can't manage to work it out...
Thanks
Craig Watson
27,930 PointsNo Problem,
Are you coding in workspaces ?
Craig
Dan Cartwright
7,009 PointsOk cheers
This code is off my laptop and not from the workspaces ?
Thanks
Dan
Craig Watson
27,930 PointsThat's fine I have just moved the code over to codepen to see how it works thats all :)
What is the purpose of the .last class? Last in the row?
Craig
Dan Cartwright
7,009 PointsOk no problem
Ye the last class is used for last in the row ? So I'm not sure if this is right or not,
Also I haven't copied over the main CSS I used for the nav and header etc...
Thanks
Dan
Ted Sumner
Courses Plus Student 17,967 PointsThank you Craig for working on this. The only thing I want to add is that it is the best practice to build for small screens first, then adjust for larger screens. The reason for this is band width usage for mobile devices. It also avoids the problem like you have here.
Craig Watson
27,930 PointsWell spotted Ted :),
That is something I haven't mentioned and possibly the most important change I made to the code was to flip it to work with a mobile first approach rather than the desktop.
Thanks Ted!
Dan Cartwright
7,009 PointsOk thanks for all the guidance on all this !
Also I'd like to gain some advice if possible or any ideas with regards to this ?
I have completed my degree in I.T multimedia, but from the course we were never taught one specific area of I.T area only small bits of each.
I have always had a very keen interest in web design, and have been working on a few small projects these last few months,
Mainly CSS/HTML and will be starting jQuery soon,
How long do you think it would realistically take to get up to speed and be ready for a junior/web designer role ?
Any advice or suggestions would be great on this ! Thanks
Dan
Craig Watson
27,930 PointsHi Dan,
Treehouse can teach you a lot in a very short space of time, but for me the most important area to get well established and familiar with is your resources.
The web changes pretty much every day, once you have a basic understanding of how your chosen languages work it is more (in my opinion) about keeping up to date and knowing where to go for help.
If I had to put a time scale on it, based on the amount I learnt in 3 months, I would say if you can get some good designs online say on CodePen and have them functioning well for all to see. Moving into a Junior role wouldn't be to far away. Experience is essential so showing what you can do first hand will help :)
Hope this helps Craig :)
Dan Cartwright
7,009 PointsDan Cartwright
7,009 Pointsok Craig that's great, cheers for all the help on this and I will test it later on to see if it works on my site, I'll let you know any other problems !
Cheers
Dan