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

CSS

Cant get my nav/menu to be fixed to the right side of the header

Here is the HTML


<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="\css\normalize.css"> <link rel="stylesheet" href="\css\css.css"> <title>ABSTRACT CATS</title>

</head>

<body>

<div class="wrap"></div> <!--Main Header-->
<header class="main_header"> <h2 class="font"> A B S T R A C T C A T S</h2> </header>

  <ul class="main_nav">
      <li>Home</li>
      <li>About</li>
      <li>Graphics</li>
    </ul>
    <div class="constainer">


    </div> 

<!--Main Content-->

</div> <footer class="main_footer"> <span>Ā© ABSTRACT CATS</span> </footer> </body> </html>



And the CSS


/* Base Styles */ body{ margin: 0; padding: 0; box-sizing: border-box; } body{ font: 15px/1.5 ariel helvetica, sans-serif; background: url('../img/IMG_5315.jpeg') no-repeat; background-size: 100% auto; background-attachment: fixed; background-size: cover; background-position: center; }

.main_header{ background: rgb(252, 252, 123); padding: .2em 0; }

/Fonts styles/ .font { color: rgb(247, 86, 212); padding: .1em; margin-left: 20px; }

/Navigation styles/

.main_nav li{ display: inline-block; padding: 2px; right: 400px; }

/Main content/ .container {

}

/Main footer/ .main_footer { background: rgb(252, 252, 123); color: rgb(247, 86, 212); padding: 2em 0; text-align: center; position: absolute; bottom: 0; width: 100%; }

/* Media Quaries */ @media(min-width: 768px){ .main_header, .container, .main_nav

{
z-index: 1000; position: fixed; float:none; width:100%; margin-top: 0;

} }


Thanks, Scott

2 Answers

Steven Parker
Steven Parker
231,269 Points

I don't see any CSS for positioning the header. For sizes below the media query breakpoint you could just float it:

.main_nav {
  float: right;
}

And for larger sizes, where the media query rules make it fixed, you could unconstrain the width and explicitly position it to the right:

  /* inside media query */
  .main_nav {
    width: initial;  /* or just don't set it to 100% to begin with */
    right: 0;
  }

Thanks Steven!

Thanks Steven!