why is my text not showing after the navigation bar?

Viewed 1262

I am very new to this whole HTML/CSS thing. After looking up a few tutorials, I managed to make a basic navigation bar but now the problem is any text I enter does not appear under the navigation bar. Am I missing something?

HTML:

body{
    margin:0;
}

nav{
    position: fixed;
    top:0;
    width:100%;
    background-color:#f2bbac ;
    float: right;
    height:70px;
    font-family: 'Quicksand', sans-serif;
}
nav ul{
   list-style: none;
   padding:0;
   margin:0;
}
nav a{
    text-decoration: none;
    font-size: 20px;  
    color: white;
    text-transform: uppercase;
}
nav a:hover{
    color:gray;
}
nav li{
    display: inline-block;
    margin-left: 40px;
    padding: 20px;
}
<!DOCTYPE html>
<html lang="en-us">
<head>
    <link href ="stylesheets/mainstyle.css"rel="StyleSheet" type="text/css">
    <title>books</title>
    <link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
</head>
<body>

    <nav>
        <ul>
            <li><a href="mainpage.html">Home</a></li>
            <li><a href="aboutpage.html">About</a></li>
            <li><a href="contact.html">Contact Us</a></li>
        </ul>
    </nav>
    <h1>hello there. testing</h1>
</body>
<script src="script.js" async defer></script>
</html>

4 Answers

It is due to position: fixed; property of nav. It makes underlying content start from top. You have to give some top-offset to h1. I have just added a spacer to body before h1

body {
    margin: 0;
}
 
nav {
    position: fixed;
 top: 0;
 width: 100%;
 background-color: #f2bbac;
 float: right;
 height: 70px;
 font-family: 'Quicksand', sans-serif;
}
  
nav ul {
 list-style: none;
 padding: 0;
 margin: 0;
}
  
nav a {
 text-decoration: none;
 font-size: 20px;
 color: white;
 text-transform: uppercase;
}
  
nav a:hover {
 color: gray;
}
  
nav li {
 display: inline-block;
 margin-left: 40px;
 padding: 20px;
}
<!DOCTYPE html>
<html lang="en-us">

<head>
    <link href ="stylesheets/mainstyle.css"rel="StyleSheet" type="text/css">
    <title>books</title>
    <link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
</head>

<body>
    <nav>
        <ul>
            <li><a href="mainpage.html">Home</a></li>
            <li><a href="aboutpage.html">About</a></li>
            <li><a href="contact.html">Contact Us</a></li>
        </ul>
    </nav>
    <div style="height: 50px;width: 100%;"></div>
    <h1>hello there. testing</h1>
</body>
<script src="script.js" async defer></script>

</html>

Applying position: fixed to an element removes it from the flow of elements on the web page and therefore your header is positioned from the very top of the page, ignoring the nav bar.

All you need to do is apply a top margin to the first element after the nav bar to poisition it below. This might be better done by placing the rest of your html within a content div and applying margin-top: 70px to that.

<div id="content">
  <h1>hello there. testing</h1>
</div>


#content {
  margin-top: 70px; /* at least the height of you nav bar */
}

jsfiddle.net/bryanwadd/r1z350y2/

Don't use float property for nav. Use it for ul instead.

try this code.

body{
    margin:0;
    padding:0;
}

nav{
    position: fixed;
    top:0;
    left:0;
    width:100%;
    background-color:#f2bbac ;
    height:70px;
    font-family: 'Quicksand', sans-serif;
}
nav ul{
   list-style: none;
   float: right;
}
nav a{
    text-decoration: none;
    font-size: 20px;  
    color: white;
    padding: 10px 10px;
    display : block;
    text-transform: uppercase;
}

Basically issue you are facing caused by having position:fixed on <nav> tag, this attribute will make the browser to remove the nav from the rendering flow and treat it as if its not there, so to make you content after it appear, all you can do is to push all elements down using padding:70px or so, working snippet:

body{
    margin:0;
    padding-top: 70px;
}

nav{
    position: fixed;
    top:0;
    width:100%;
    background-color:#f2bbac ;
    float: right;
    height:70px;
    font-family: 'Quicksand', sans-serif;
}
nav ul{
   list-style: none;
   padding:0;
   margin:0;
}
nav a{
    text-decoration: none;
    font-size: 20px;  
    color: white;
    text-transform: uppercase;
}
nav a:hover{
    color:gray;
}
nav li{
    display: inline-block;
    margin-left: 40px;
    padding: 20px;
}
<!DOCTYPE html>
<html lang="en-us">
<head>
    <link href ="stylesheets/mainstyle.css"rel="StyleSheet" type="text/css">
    <title>books</title>
    <link href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap" rel="stylesheet">
</head>
<body>

    <nav>
        <ul>
            <li><a href="mainpage.html">Home</a></li>
            <li><a href="aboutpage.html">About</a></li>
            <li><a href="contact.html">Contact Us</a></li>
        </ul>
    </nav>
    <h1>hello there. testing</h1>
</body>
<script src="script.js" async defer></script>
</html>

Related