How come my label and input are showing up in my navigation bar?

For my assignment, I am designing a website layout and facing an issue where the text appears behind the navigation bar instead of below it. I have tried adjusting the margin-bottom to 50px with important tags and setting the nav bar as static.

Despite trying various settings and configurations, including messing around with different options, I haven't found a solution that works effectively.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Website Title</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,100i,300,300i,400,400i,500,500i,700,700i,900,900i&display=swap" rel="stylesheet">
  </head>
   <header>
        <nav>

            <ul>
                <li class="website-title"><a href="#">Website Title</a></li>
                <li><a href="Home">Home</a></li>
                <li><a href="About">About</a> </li>
            </ul>
         </nav>
    </header>

  <body>
    <div class="search-bar"> 
      <input type="text" placeholder="Search for Jobs"> </input>
      <label> Search Jobs </label> </div>


  </body>
</html>



head{
font-family: 'Roboto', sans-serif;
height:100vh;

}

nav{
  top:0;
  right:0;
  left:0;
  background-color:#dddddd;
  position:fixed;
  padding:10px;
}

ul {
  width:100vw;
    margin: 0;
    padding: 0;
}
​
li {
    list-style-type: none;
    float: right;
    text-align:center;

}

.website-title {
  float:left;
  text-align:center;
  font-size:25px;
}

li a {
    display:block;
    padding:8px;
    color:purple;
    font-size:20px;
    text-decoration:none;

    }

Answer №1

Since your navigation is set to position: fixed;, it does not affect the positioning of the rest of your content on the page. Elements that are absolutely positioned, such as absolute, sticky, or fixed, do not interact with the DOM in the same way as standard elements do. To address this issue, you can add a margin-top to your content like so:

header{
font-family: 'Montserrat', sans-serif;
height: 90%vh;

}

nav{
    top:0;
    right:0;
    left:0;
    background-color:#f1f1f1;
    position:fixed;
    padding:10px;
}

ul {
    width:100%vp;
    margin: 0;
    padding: 0;
}

li {
    list-style-type: none;
    float: right;
    text-align:center;

}

.gregs-title{
    float: left;
    text-align:center;
    font-size:25px;
}

li a {
    display:block;
    color:purple;
    font-size:20px;
    text-decoration:none;
    padding:8px;
}

body{
    margin-top: 60px;
}
<!DOCTYPE html>
<html>
  <header>
    <title>Custom Header</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
  </header>

  <body>
     <nav> 
        <ul>
            <li class="gregs-title">Greg's Site</li>
            <li><a href="About.asp">About</a><li><a href="Contact.asp">Contact</a>
         </ul>
    </nav>
  
    <div class="search-bar"> 
      <input type="text" placeholder="Search for items"> </input>
      <label> Search Items </label> 
   </div>


  </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for choosing Week Range values with Selenium WebDriver

Currently, I am working with Selenium WebDriver and I am trying to figure out how to select week range values from a dropdown menu at once. I have a dropdown called Period, which, when selected, automatically reveals additional dropdowns for From week and ...

Unable to wrap the strings from the database in a span element

I have a challenge where I need to enclose the first and last strings that represent the title and price of a product within a div using a span tag. These strings are dynamic, sourced from a database, and differ for each product. I have attempted to use th ...

Having trouble with SVG background image not displaying properly and positioning correctly?

I need help fitting an svg as a background into an element that is 80% of the screen width. Here is the desired final result: The svg effect only works correctly when I reduce the width, but then it breaks in two. I want the svg to appear at 80% width a ...

The API response was blocked due to the CORS header "Access-control-allow-origin."

I have an index.html file that is used for making HTML and Ajax calls. When I run the file through localhost, the API works perfectly. However, if I directly open the index.html file in Google Chrome or Mozilla Firefox, I encounter a CORS (Cross-Origin Re ...

Issue with menu height persisting while resizing screen

For my responsive design project, I am implementing a menu that switches to a menu button when the width is less than or equal to 768px. Currently, I am using jQuery to dynamically adjust the height of the menu when the menu button is clicked. The jQuery ...

Is it true that event.stopPropagation does not function for pseudoelements?

I am facing an issue with event handling in my ul element. The ul has three li children elements, and the ul itself has a useCapture event handler for click. In the click event handler, I successfully stop the event using event.stopPropagation(), and every ...

Insert a new <tr> element into a dynamic table using PHP and jQuery without the need to refresh the page

I am attempting to dynamically insert a row into an existing table when a button is clicked. The rows in the table are created dynamically based on data retrieved from a PHP script. My approach involves making an ajax call to the insert_tr.php script, whi ...

Guide on Applying a Dynamic Color in VueJs 3 Composition API/Vuetify Using CSS

Currently, my project utilizes Vue 3 with the composition API and Vuetify for the UI. I am looking to utilize a color that is already defined in a Vuetify theme variable within my CSS, similar to how I have done it previously in JavaScript. Although I at ...

Mobile display exhibiting glitches in animation performance

I have implemented an animation in the provided code snippet. const logo = document.querySelector('.logo'); const buttons = document.querySelectorAll('.loadclass'); const html = document.querySelector('html') const cornerme ...

Exploring through a table using JavaScript

I am struggling to search a table within my HTML for a specific term. The code I have works to an extent, but it does not account for alternatives such as searching for "what is that" when I type in "What is that". Additionally, I need the script to ignor ...

Issue with hashtag in regular expressions

Looking for a way to identify and link hashtag words with an anchor tag? Here's a snippet showcasing the concept: <p class="display"></p> var content = "I enjoy #blueSky. My favorite color is #green. #sky is amazing"; ...

A collapsible select list with checkboxes for children items

I am currently developing a website using Vue.js, HTML, and SCSS. I am looking to implement a drop-down functionality similar to the animated example provided in the gif below: https://i.stack.imgur.com/Mia2D.gif The gif demonstrates how the drop-down me ...

Seeking assistance with implementing Styles using the .css() function in Jquery. Any guidance is appreciated

This particular style is exactly what I am looking for. body{ background: url("img/Background_Home.jpg") no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; ...

Swapping out data points using JQuery

What could be causing line 10 to return null? Click here for the code file The code seems to function properly with line 40, but not with line 10. ...

Maximizing Compatibility of CSS3 Responsive Image Sprites for Firefox

Take a look at the Demo. Make sure to test it on both Chrome and Firefox to experience the difference. I've created a div element with the following CSS classes to make a responsive sprite of images: .what-wwb-logo, .what-national-geographic-logo, . ...

Design a big-sized button using Bootstrap framework

Is there a way to design a big, responsive button using Bootstrap? Similar to the example image linked below ...

The onClick event is not executing my function

Having trouble triggering the onclick() event when trying to modify table data using ajax. Here's the code snippet: (the onclick() event is located in the last div tag) @{ ViewBag.Title = "Edit_Room"; Layout = "~/Views/Shared/_LayoutAdmin.csh ...

Alert: An error message is displayed despite completing the required field

My apologies in advance as I am new to coding and there may be a glaring mistake in my current project. I am creating a survey that requires participants to enter their age. The demographic data questions are organized in a table format, with code borrowed ...

Best practices for evenly distributing images within a navigation bar?

Within a horizontal navbar, I have various small images that are currently spaced out with different intervals between them. Each image has its own unique spacing from the others. I am looking to achieve consistent spacing between each image in this horiz ...

Using inline style instead of relying on the quill editor's built-in classes, as classes may not be accessible in order to render HTML effectively

I have integrated the ngx-quill editor into my Angular project as the rich text editor. I plan to save the generated HTML in a database and display it on various browsers using innerHTML. Since the styling is done through a class attribute that references ...