0

I am using pixel perfect to try to duplicate a web page for learning purposes. I am having a really hard time trying to create this. For starters, my text will not stay centered on the nav bar. I think it may be an issue with my header. I might have combined the header and nav by accident. I'm not sure how to fix it.

The page I am trying to copy

My html:

  <body>
  <div id="wrapper">
    <header>
    <div id="bluebox"><h1>Main Title Here</h1></div>
    <div id="outerbox"></div>
    <div id="navbox"></div>
    </header>
    <div class="navigation-bar">
        <nav>
            <ul>
                <li><a href="home.html">Home</a></li>
                <li><a href="about.html">About</a></li>
                <li><a href="portfolio.html">Portfolio</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </nav>
    </div>

My css:

/* general */
*{margin: 0; padding: 0;}
body {font-size: 100%; line-height: 1.5em; font-family: 'arial'; }
article, aside, figure, footer, header, main, menu, nav, section, video {display: block;}

/* wrapper */
#wrapper {width: 1024px; margin: 0 auto; }

/* header */
#wrapper header {height: 50px; padding-top: 128px; padding-right: 0px;
padding-bottom: 0px; padding-left: 0px;}
#wrapper h1 {font-family: "arial"; color: #FFF; top: 70px; position: absolute; padding-left: 195px; font-size: 2.75em;}
#bluebox{
 background-color: #23b6eb;
 width: 1020px;
 height: 140px;
 position: absolute;
 top: 30px;
}
#outerbox{
 background-color: #5d5a5a;
 width: 1020px;
 height: 30px;
 position: absolute;
 top: 0px;
}

/* navigation */

#navbox{
 background-color: #BBB;
 width: 1020px;
 height: 40px;
 position: absolute;
 top: 170px;
}

.navigation-bar {display: inline-block; font-weight: bold; font-size: 1.2em; vertical-align: center; text-align: center;}
nav ul li span, nav ul li a {text-decoration: none; color: #000; } 
3
  • 1
    Why are you using position: absolute? Your code is so wrong! :( Don't use position: absolute for whatever reason you have right now. Why? Looks for me is a wrapper with a padding, and background, and then header, content, and footer has the individual colours. Commented Apr 18, 2017 at 17:51
  • Yeah I kind of have no idea what I am doing. I never had to create something from scratch before. I still don't know how to fix it Commented Apr 18, 2017 at 17:53
  • Check out my answer. Commented Apr 18, 2017 at 17:58

1 Answer 1

2

Same one with the right way. I have changed the following:

  1. Completely get rid of the position: absolute.
  2. Replace all the height using line-height.
  3. Get rid of unnecessary tags, like outer-box, etc.
  4. Use semantic tags, wherever possible.

/* general */

* {
  margin: 0;
  padding: 0;
}

body {
  font-size: 100%;
  line-height: 1.5em;
  font-family: 'arial';
}

article, aside, figure, footer, header, main, menu, nav, section, video {
  display: block;
}

/* wrapper */
#wrapper {
  width: 1024px;
  margin: 0 auto;
  padding: 20px 0;
  background-color: #5d5a5a;
}

/* header */
#wrapper header {
  background-color: #23b6eb;
}

#wrapper header h1 {
  font-family: "arial";
  color: #fff;
  font-size: 2.75em;
  text-align: center;
  line-height: 2.5;
}


/* navigation */
nav ul {
  text-align: center;
  background-color: #ccc;
}

nav ul li {
  display: inline-block;
  padding: 0 25px;
}

nav ul li a {
  text-decoration: none;
  color: #000;
}
<div id="wrapper">
  <header>
    <h1>Main Title Here</h1>
  </header>
  <nav>
    <ul>
      <li><a href="home.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="portfolio.html">Portfolio</a></li>
      <li><a href="contact.html">Contact</a></li>
    </ul>
  </nav>
</div>

Preview

preview

Sign up to request clarification or add additional context in comments.

8 Comments

I tried copying and pasting your code, but it changed all my colors and the layout of the header and nav. It did center my text though, but everything else changed.
@MollyMarie Can you run the code snippet and put it on the full screen and see if shows the correct expected output? I verified with the image you had given as reference.
@MollyMarie Make a JSBin with your current code with mine, I can help you with it. :) This is the current version, for your perusal: jsbin.com/fekahemura/edit?html,css,output
@MollyMarie You should be more interested in the /* navigation */ part of the CSS.
It worked this time. It looks like yours now, problem is though, it has made my body text all align all the way to left. Not sure why
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.