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 trialMikey Neilson
Front End Web Development Techdegree Student 12,642 Pointsnth-child in media queries
I'm have trouble with nth-child in media queries i have two break points first one is min-width 768px and i have a gallery with a two column layout with gallery li:nth-child(2n+1). But when i go to my break point of min-width 1024px my gallery is a three column layout but with galley li:nth-child(2n+1) set in 768px media queries my three column lay out stays as two column. Iv add my media queries css Any help with this would be great thank you .
@media ( min-width:768px ) {
/*-- Nav-bar 768px --*/
.name {
font-size: 2em;
margin-bottom: 5px;
}
.main-nav {
text-align: center;
}
.main-nav li {
font-size: .8em;
background: #000;
display: inline-block;
margin: 0 auto;
}
.main-nav li a {
font-weight: bold;
}
/*-- Sub-Header 768px --*/
.sub-header {
width: 90%;
margin: 0 auto;
background: #2BA4CC;
}
.col {
float: right;
}
.set,
.blurb {
width: 50%;
}
.gallery {
max-width: 90%;
background: #000;
margin: 40px auto;
}
.gallery li {
width: 45%;
margin: 2.5%;
padding-top: 4px;
float:left;
}
.gallery li:nth-child(2n+1) {
clear:left;
}
.sub-nav {
margin-right: 15px;
}
.sub-nav li {
float: right;
display: inline-block;
padding: 20px 15px;
}
.top {
display: none;
}
.clearfix {
content: " ";
display: table;
clear: both;
}
}
@media (min-width: 1024px) {
.name {
font-size: 1.8em;
float: left;
padding: 10px 0 0 20px;
margin-left: 20px;
}
.main-nav ul {
margin: 0;
padding: 0;
overflow: hidden;
float: right;
}
.main-nav li {
display: inline-block;
}
.main-nav li a {
font-size: 1.25em;
text-align: center;
padding: 10px 15px;
text-decoration: none;
}
.contanier {
background: #2BA4CC;
}
.blurb {
font-size: 1.4em;
font-weight: bold;
}
.gallery li {
width: 26.333%;
padding-top: 20px;
float:left;
}
.clearfix {
content: " ";
display: table;
clear: both;
}
}
3 Answers
Raúl Barrera C.
18,943 PointsHi! You must cancel the clear:left in the 1024 query. You can make this adding:
.gallery li:nth-child(2n+1) {
clear:none;
}
to the 1024 media query.
Mikey Neilson
Front End Web Development Techdegree Student 12,642 PointsHi Rau thank you that's got my three columns back yea :) but now face another problem as i have a :
.gallery li:hover {
border: 2px solid #fff;
background-color: #333;
}
now when i hover over li they are all over the place any idea how to stop that without clear:left.
Manythanks
Raúl Barrera C.
18,943 PointsHi, It's a problem whit the box model, that adds the 2px border on hover. To fix this add this rule to your stylesheet
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
I hope this help! :D
Mikey Neilson
Front End Web Development Techdegree Student 12,642 PointsThank you Rau helps loads cheers :)