Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,164 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!