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 trialDean Conway
3,301 Pointsmy columns are not flush?
Hi,
When I entered the same code as explained in this video, I ended up with staggered vertical heights in my columns, so they were not flush along the top as in the video, this was most notable after I had a background color applied to each column,
Why is this happening?
16 Answers
Joe Consterdine
13,965 PointsHi Dean,
looks much better!
In regards the line length been too long at that breakpoints you mentioned, what I usually do is have a container around my content and then decrease the width so the line-length is shorter.
So try this:
- I've added a div container around your columns with a class of 'main-content-wrapper'.
- I've given it a width of 80% which will decrease the lines going so side. Default is 100%.
- I've given it margin: 0 auto; which will center the container.
- When your columns go side by side at around 1210px I've given it a width of 100% again and reset the margin as we only wanted those styles for when they go on top of each other in smaller sizes.
You can play around with the widths as you please. You may feel it's too narrow at really smaller sizes so you can try 90% instead of 80% etc.
If you wanted to go a step further and make this even better I would suggest a couple of things:
- Remove the bullet points on your menu items at smaller screen sizes.
- Make the menu items line up with the 'Best City Guide' logo above.
Good luck!
<!DOCTYPE html>
<html>
<head>
<title>Best City Guide</title>
<link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="wrap">
<header class="main-header">
<div class="container">
<h1 class="name"><a href="#">Best City Guide</a></h1>
<ul class="main-nav">
<li><a href="#">ice cream</a></li>
<li><a href="#">donuts</a></li>
<li><a href="#">tea</a></li>
<li><a href="#">coffee</a></li>
</ul>
</div>
</header>
<div class="container">
<div class="main-content-wrapper">
<div class="primary col">
<h2>Welcome!</h2>
<p>Everything in this city is worth waiting in line for.</p>
<p>Cupcake ipsum dolor sit. Amet chocolate cake gummies jelly beans candy bonbon brownie candy. Gingerbread powder muffin. Icing cotton candy. Croissant icing pie ice cream brownie I love cheesecake cookie. Pastry chocolate pastry jelly croissant.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
</div><!--/.primary-->
<div class="secondary col">
<h2>Great food</h2>
<p>Croissant macaroon pie brownie. Cookie marshmallow liquorice gingerbread caramels toffee I love chocolate. Wafer lollipop dessert. Bonbon jelly beans pudding dessert sugar plum. Marzipan toffee dragée chocolate bar candy toffee pudding I love. Gummi bears pie gingerbread lollipop.</p>
<p> Fruitcake jelly-o croissant soufflé. Biscuit jujubes dragée. Sesame snaps tootsie roll chocolate bar cake tart macaroon pudding. Ice cream gummies jujubes cupcake. Cake marshmallow cookie lollipop tart.</p>
</div><!--/.secondary-->
</div>
</div><!--/.container-->
</div><!--/.wrap-->
<footer class="main-footer">
<span>©2015 Residents of The Best City Ever.</span>
</footer>
</body>
</html>
/* =================================
Base Styles
==================================== */
* {
box-sizing: border-box;
}
body {
font-family: 'Varela Round', sans-serif;
line-height: 1.6;
color: #3a3a3a;
}
p {
font-size: .95em;
margin-bottom: 1.5em;
}
h2,
h3,
a {
color: #093a58;
}
h2,
h3 {
margin-top: 0;
}
a {
text-decoration: none;
}
/* =================================
Base Layout Styles
==================================== */
/* ---- Navigation ---- */
.name {
font-size: 1.25em;
}
.name,
.main-nav li {
text-align: center;
background: #fff;
margin-top: 6px;
margin-bottom: 6px;
}
.main-nav a {
font-size: .95em;
color: #3acec2;
text-transform: uppercase;
}
.main-nav a:hover {
color: #093a58;
}
.name a,
.main-nav a {
padding: 10px 15px;
display: block;
}
/* ---- Layout Containers ---- */
.col {
background-color: #DFF7F5;
display: block;
width: 100%;
padding: 1em;
margin-bottom: 1em;
}
.container {
padding-left: 1em;
padding-right: 1em;
}
.main-content-wrapper {
width: 80%;
margin: 0 auto;
}
.main-header {
padding-top: 1.5em;
padding-bottom: 1.5em;
background: #3acec2;
margin-bottom: 30px;
}
.main-footer {
text-align: center;
padding: 2em 0;
background: #d9e4ea;
}
/* =================================
Media Queries
==================================== */
@media (min-width: 769px) {
.wrap {
min-height: calc(100vh - 89px);
}
.container {
width: 80%;
max-width: 1150px;
margin: 0 auto;
}
.name,
.main-nav,
.main-nav li {
display: inline-block;
}
.name {
width: 240px;
margin-right: 50px;
}
.main-nav li {
margin-right: 12px;
}
}
@media (min-width: 1210px) {
.col {
background-color: #DFF7F5;
display: inline-block;
width: 45%;
margin-right: 1em;
vertical-align: top;
min-height: 700px;
}
.main-content-wrapper {
width: 100%;
margin: inherit;
}
}
Joe Consterdine
13,965 PointsHi Dean,
is that all of it? For e.g in your HTML where's the doctype, link tags etc.
If you post literally all of it I can just copy it all in to my text editor and see what's going wrong.
Cheers!
Joe Consterdine
13,965 PointsCool, but where is the rest of the HTML?
Joe Consterdine
13,965 PointsYeah no worries I'll have a look.
Joe Consterdine
13,965 PointsHi Dean,
I've found the problem.
You have this:
{ box-sizing: border-box; }
So you're not actually selecting any element here. You always need to select an element before the brackets for e.g.
p { color: red; }
So as I'm sure you know we're selecting the paragraph element here. in the example above you've written the selector but it isn't targeting anything.
You need to add a star infront of it like this:
* { box-sizing: border box; }
If you don't already know the star will select every single element you have and add this selector to it.
Do you know what border-sizing: border-box does? If not let me know and I'll explain.
Try the code first, make sure it works and get back to me.
Joe
Joe Consterdine
13,965 PointsJust add it here but do it properly.
How are you adding the code here?
you need to add three backticks followed by the language. So in this example three backticks followed by css with no spaces.
Then add all your css code.
Then add three more backticks underneath your code to close it.
Got that?
Thanks
Joe Consterdine
13,965 PointsYou need to add 'css' after those three backticks at the start. And you have added them at the end of your code also?
Dean Conway
3,301 Points/* =================================
Base Styles
==================================== */
* {
box-sizing: border-box;
}
body {
font-family: 'Varela Round', sans-serif;
line-height: 1.6;
color: #3a3a3a;
}
p {
font-size: .95em;
margin-bottom: 1.5em;
}
h2,
h3,
a {
color: #093a58;
}
h2,
h3 {
margin-top: 0;
}
a {
text-decoration: none;
}
/* =================================
Base Layout Styles
==================================== */
/* ---- Navigation ---- */
.name {
font-size: 1.25em;
}
.name,
.main-nav li {
text-align: center;
background: #fff;
margin-top: 6px;
margin-bottom: 6px;
}
.main-nav a {
font-size: .95em;
color: #3acec2;
text-transform: uppercase;
}
.main-nav a:hover {
color: #093a58;
}
.name a,
.main-nav a {
padding: 10px 15px;
display: block;
}
/* ---- Layout Containers ---- */
.container {
padding-left: 1em;
padding-right: 1em;
}
.main-header {
padding-top: 1.5em;
padding-bottom: 1.5em;
background: #3acec2;
margin-bottom: 30px;
}
.main-footer {
text-align: center;
padding: 2em 0;
background: #d9e4ea;
}
/* =================================
Media Queries
==================================== */
@media (min-width: 769px) {
.wrap {
min-height: calc(100vh - 89px);
}
.container {
width: 80%;
max-width: 1150px;
margin: 0 auto;
}
.name,
.main-nav,
.main-nav li {
display: inline-block;
}
.name {
width: 240px;
margin-right: 50px;
}
.main-nav li {
margin-right: 12px;
}
.col {
background-color: #ccc;
display: inline-block;
width: 50%;
margin-right: -5px;
vertical-align: top;
padding-left: 1em;
padding-right: 1em;
}
}
Joe Consterdine
13,965 PointsHi Dean,
I don't see any problem? It works fine for me.
Can you take a screenshot of what you see on your screen and explain again what is wrong? With that code the columns float side by side and are aligned at the top.
Thanks Joe
Dean Conway
3,301 PointsHi Joe,
I have taken a screenshot which better captures what I mean, but there's no functionality in this forum to add attachments to comment??
Regards Dean
Dean Conway
3,301 Pointshttp://postimg.org/image/6mhjqs1gl/
What I'm saying is, even though there might not be anything technically wrong in the code, I do find its an issue on a aesthetic/visual level, which would be apparent if I wanted to add a background colour to both columns, if that was to be part of the design,.
So how would I make both columns of equal height? even though one has less content than the other, preferably without using a fixed height property which would be restrictive in some respects.
Joe Consterdine
13,965 PointsHi Dean,
I see your point.
so do this:
.col {
background-color: #ccc;
display: inline-block;
width: 50%;
margin-right: -5px;
vertical-align: top;
padding-left: 1em;
padding-right: 1em;
min-height: 500px;
}
so I've given your columns a min-height property. What this will do will basically say 'ok I want both columns to be AT LEAST 500px high... but if more content is added then keep getting higher. This is counters your problem of having a fixed height.
Now when your go to smaller screen sizes you will notice that you get the same problem, and the reason for this is because the screen size is smaller then your columns get higher naturally as the content in your columns is finding it hard to fit everything in.
So here you have two options:
1.Make your columns block level elements so they stack on top of each other and span the full width of the screen. This is actually normal practise for mobile screen sizes anyway. You will rarely see two columns floated side by side at smaller screen sizes because the content won't fit nicely.
The second option is to increase the min-height value, but you may find it difficult to make that look nice at all sizes. I prefer the first option.
Let me know how you get on.
Thanks Joe
Dean Conway
3,301 PointsHi Joe,
Thanks for sending through that suggestion, so in the end I went with option 1 as it seemed the most natural way to do it.
So I put into practice what you suggested and in the end I got quite a nice result from it, what I did in addition was to add a second media query, at the point where the first column snaps to match the height of the second column but only at the point where the width of the browser is wide enough to allow that to happen, because of the fact the first column deliberately had more content in it, the idea was to prevent the staggered effect ever appearing regardless of the screen size.
The only thing is in MHO is that the line length gets a bit long in between the 850px - 1209px before it snaps back into the more digestible side by side cards. But apart from this is the result I was looking for so thanks.
I would be interested to hear your thoughts on it.
Regards Dean
Dean Conway
3,301 Points<!DOCTYPE html>
<html>
<head>
<title>Best City Guide</title>
<link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="wrap">
<header class="main-header">
<div class="container">
<h1 class="name"><a href="#">Best City Guide</a></h1>
<ul class="main-nav">
<li><a href="#">ice cream</a></li>
<li><a href="#">donuts</a></li>
<li><a href="#">tea</a></li>
<li><a href="#">coffee</a></li>
</ul>
</div>
</header>
<div class="container">
<div class="primary col">
<h2>Welcome!</h2>
<p>Everything in this city is worth waiting in line for.</p>
<p>Cupcake ipsum dolor sit. Amet chocolate cake gummies jelly beans candy bonbon brownie candy. Gingerbread powder muffin. Icing cotton candy. Croissant icing pie ice cream brownie I love cheesecake cookie. Pastry chocolate pastry jelly croissant.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
<p>Cake sesame snaps sweet tart candy canes tiramisu I love oat cake chocolate bar. Jelly beans pastry brownie sugar plum pastry bear claw tiramisu tootsie roll. Tootsie roll wafer I love chocolate donuts.</p>
</div><!--/.primary-->
<div class="secondary col">
<h2>Great food</h2>
<p>Croissant macaroon pie brownie. Cookie marshmallow liquorice gingerbread caramels toffee I love chocolate. Wafer lollipop dessert. Bonbon jelly beans pudding dessert sugar plum. Marzipan toffee dragée chocolate bar candy toffee pudding I love. Gummi bears pie gingerbread lollipop.</p>
<p> Fruitcake jelly-o croissant soufflé. Biscuit jujubes dragée. Sesame snaps tootsie roll chocolate bar cake tart macaroon pudding. Ice cream gummies jujubes cupcake. Cake marshmallow cookie lollipop tart.</p>
</div><!--/.secondary-->
</div><!--/.container-->
</div><!--/.wrap-->
<footer class="main-footer">
<span>©2015 Residents of The Best City Ever.</span>
</footer>
</body>
</html>
Dean Conway
3,301 Points/* =================================
Base Styles
==================================== */
* {
box-sizing: border-box;
}
body {
font-family: 'Varela Round', sans-serif;
line-height: 1.6;
color: #3a3a3a;
}
p {
font-size: .95em;
margin-bottom: 1.5em;
}
h2,
h3,
a {
color: #093a58;
}
h2,
h3 {
margin-top: 0;
}
a {
text-decoration: none;
}
/* =================================
Base Layout Styles
==================================== */
/* ---- Navigation ---- */
.name {
font-size: 1.25em;
}
.name,
.main-nav li {
text-align: center;
background: #fff;
margin-top: 6px;
margin-bottom: 6px;
}
.main-nav a {
font-size: .95em;
color: #3acec2;
text-transform: uppercase;
}
.main-nav a:hover {
color: #093a58;
}
.name a,
.main-nav a {
padding: 10px 15px;
display: block;
}
/* ---- Layout Containers ---- */
.col {
background-color: #DFF7F5;
display: block;
width: 100%;
padding: 1em;
margin-bottom: 1em;
}
.container {
padding-left: 1em;
padding-right: 1em;
}
.main-header {
padding-top: 1.5em;
padding-bottom: 1.5em;
background: #3acec2;
margin-bottom: 30px;
}
.main-footer {
text-align: center;
padding: 2em 0;
background: #d9e4ea;
}
/* =================================
Media Queries
==================================== */
@media (min-width: 769px) {
.wrap {
min-height: calc(100vh - 89px);
}
.container {
width: 80%;
max-width: 1150px;
margin: 0 auto;
}
.name,
.main-nav,
.main-nav li {
display: inline-block;
}
.name {
width: 240px;
margin-right: 50px;
}
.main-nav li {
margin-right: 12px;
}
}
@media (min-width: 1210px) {
.col {
background-color: #DFF7F5;
display: inline-block;
width: 45%;
margin-right: 1em;
vertical-align: top;
min-height: 700px;
}
}
Dean Conway
3,301 PointsHi Joe,
Thanks for those suggestions, and really appreciate the detail of thought you've put into your replies, helps me to understand these concepts better, I will try those ideas when I get a chance.
Thanks Dean
Joe Consterdine
13,965 PointsJoe Consterdine
13,965 PointsHi Dean,
post all your code and I'll take a look.
Thanks