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 trialDaryl Burrows
2,564 Pointsgeneral sibling selector help please!
I'm creating a one page website with transitions to show/hide content and I am stumped as to a piece of styling... Why do I have to place the Header section at the bottom of the html document (under the content sections) for styling to work when using the general sibling selector to style the current section in the navigation? Its driving me nuts trying to figure it out! - This is the html:
<div id="header">
<h1>Page Transitions with CSS3</h1>
<ul id="navigation">
<li><a id="link-home" href="#home">Home</a></li>
<li><a id="link-portfolio" href="#portfolio">Portfolio</a></li>
<li><a id="link-about" href="#about">About Me</a></li>
<li><a id="link-contact" href="#contact">Contact</a></li>
</ul>
</div>
and this is the css:
home:target ~ #header #navigation #link-home,
portfolio:target ~ #header #navigation #link-portfolio,
about:target ~ #header #navigation #link-about,
contact:target ~ #header #navigation #link-contact{
background: #000;
color: #fff;
}
Ive googled it all day with no answers lol
2 Answers
Kyle Chadha
2,257 PointsDaryl can you post the full HTML code? Usually when the relative positioning of code in a document is affecting your styling it means something else in the document is trumping your intended styles.
So, in other words -- you style your header with the general sibling selector, but as the browser continues to read the page, something else in it overrides the initial styling. This has to do with the cascade priority: Importance, Specificity, and Source Order.
I'm not sure if this exists -- but if there was a debugger by which you could load the code line by line, then you could pinpoint at what point your intended styling is being overridden.
Cheers,
Kyle
Kyle Chadha
2,257 PointsHrmm having a bit of trouble understanding what you're describing. What styling specifically do you see changing when you rearrange your sections?
In any case -- unless it's getting manipulated when you're posting in the forum, your syntax also seems like it's off. Check this site for proper syntax when using child / sibling selectors. http://www.w3schools.com/cssref/css_selectors.asp
Daryl Burrows
2,564 Pointsthanks but if you could take a look at this tutorial and explain to me why he said this - "The reason for having such an βunorderedβ structure by adding the header to the end, is that we make the navigation βreachableβ using the general sibling selector (~), so that we can color the respective items differently." I would be very happy!
tutorial in question - http://tympanus.net/codrops/2012/01/30/page-transitions-with-css3/
Kyle Chadha
2,257 PointsHrmm sorry Daryl -- I took a look at it but I'm not sure. Still learning myself. Perhaps if you ask this question on stackoverflow (http://stackoverflow.com/) you'll have better luck?
Daryl Burrows
2,564 PointsIts ok dude, thanks for your help, Ive posted on stack overflow as per your suggestion. Again thanks for taking the time to help, I appreciate it :)
Daryl Burrows
2,564 PointsDaryl Burrows
2,564 PointsOk here is the full code, If I move the header navigation section above any of the 4 sections then the styling is not applied to the sections below it, that is why it is sitting at the bottom to be able to style them. I think the problem is to do with the target: pseudo class and general sibling selector but I dont understand why and I would really like too!
</body>
html{ height: 100%; }
body{ font-family: 'Electrolize', Arial, sans-serif; font-weight: 400; font-size: 15px; color: #fff; background-color: #ffcb00; width: 100%; }
a{ text-decoration: none; }
header{
}
header h1{
}
navigation {
}
navigation a {
}
navigation a:hover {
background: #ddd;
}
.panel { min-width: 100%; height: 98%; overflow-y: auto; overflow-x: hidden; margin-top: -150%; position: absolute; background: #000; box-shadow: 0px 4px 7px rgba(0,0,0,0.6); z-index: 2;
}
.panel:target{ margin-top: 0%; background-color: #ffcb00; }
.content{ right: 40px; left: 280px; top: 0px; position: absolute; padding-bottom: 30px; } .content h2{ font-size: 110px; padding: 10px 0px 20px 0px; margin-top: 52px; margin-bottom: 25px; color: #fff; color: rgba(255,255,255,0.9); text-shadow: 0px 1px 1px rgba(0,0,0,0.3); } .content p{ font-size: 18px; padding: 10px; line-height: 24px; color: #fff; display: inline-block; background: black; padding: 10px; margin: 3px 0px; }
home:target ~ #header #navigation #link-home,
portfolio:target ~ #header #navigation #link-portfolio,
about:target ~ #header #navigation #link-about,
contact:target ~ #header #navigation #link-contact
{ background: #000; color: #fff; }