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 trial
Tracy Excell
Front End Web Development Techdegree Graduate 15,333 PointsHow to use flexbox to alter my header for a lager screen size
Hello,
I have been trying to use flexbox to alter my header for a larger screen size. I want it in a horizontal line at the top of the page. However in my media query, it will not work. It has in other areas of my project. Can someone please let me know where I am going wrong? Thank you.
Relevant code:
HTML
<div id="header_info"> <header class="main-header"> <h1>Tracy Excell</h1> <ul class="nav"> <li><a id="home">Home</a></li> <li><a href="#portfolio">Portfolio</a></li> <li><a href="#contact">Contact</a></li> </ul> </header>
Base css /* main header and navigation styles*/
.nav li{ list-style-type: none; border: 2px solid white; background-color: white; padding: .5em; margin-bottom: .5em; margin-left: -2em; width: 70vw;
} .nav li a{ display: block; text-decoration:none; color: black; text-align: center; margin: 0 auto; }
.nav li a:hover { color: #456e6e; }
NAV CSS
header_info {
max-height: 700px;
margin: -1em;
}
.main-header { display: flex; } .main-header h1 {
justify-content: flex-start;
}
.nav li {
justify-content: flex-end;
}
1 Answer
Stephan L
17,821 PointsHi there, It's a little hard to tell for sure the way the code is formatted, but it looks like you are calling the justify-content rule on the children (<h1>) and children of the children (the .nav <li> elements) of the flex container, .main-header. .Main-header is the flex container, and therefore <h1> and .nav are the flex items. Flex properties called on .main-header will not control the position of the <li> children of .nav. Also, justify-content is used on the flex container element to control the position of its immediate children. Try using justify-content on the flex container, .main-header.
That may have been a little verbose, so here's what I mean:
.main-header //this is the flex container, where you should define justify-content for the flex items
-------h1 //this is a child of the flex-container, a flex item
------.nav //this is a child of the flex-container, a flex item
--------------li... //these are children of .nav and therefore are not flex items (unless you also make .nav a flex container
Based on how you're calling justify-content, it looks like you want your h1 element to align left and the .nav li items to align right? If so, try calling justify-content: space-between on the .main-header flex container.