Integrated Navigation Bar and Header

I'm struggling to figure out a way to integrate my navigation bar and header title. Essentially, I want the text of my header to overlap with or be part of my navigation bar, while also ensuring that both elements remain fixed at the top of the page when scrolling. Despite my efforts, I haven't been able to make much progress in manipulating the CSS and HTML for this specific design.

header {
        /*insert something here?*/
      }

      nav {
        background-image: url("header.jpg");
        background-position: center;
        padding: 1%;
        overflow: hidden;
      }

      nav a {
        float: left;
        display: block;
        color: orange;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
        font-size: 17px;
        font-family: helvetica;
        letter-spacing: 2px;
      }

      nav li,
      nav ul {
        list-style: none;
      }

      nav a:hover {
        background-color: #ddd;
        color: black;
      }

      nav .material-icons {
        display: none;
        font-size: 36px;
        color: blue;
      }

      @media screen and (max-width: 600px) {
        nav a:not(:first-child) {
          display: none;
        }
        nav .material-icons {
          float: left;
          display: block;
        }
      }
<header>
        Knox Enterprises Inc.
        <nav>
          <i class="material-icons">menu</i>
          <a href="index.html">Home</a>
          <a href="About.html">About</a>
          <a href="Contact.html">Contact</a>
        </nav>
      </header>

Answer №1

To achieve the desired layout, you can set the header to display: flex and use justify-content: space-between. This will separate the text and navigation elements. Alternatively, you can remove the justify content property to have the text and nav side-by-side on the left, or use justify-content: center to center alignment, or justify-content: flex-end to align them to the right. Place the text within an h1 or another appropriate element and then add position: fixed; width: 100% to keep it pinned at the top of the page.

body {
  min-height: 500vh;
  background: #eee;
  margin: 0;
}
header {
  display: flex;
  justify-content: center;
  position: fixed;
  width: 100%;
  background: #fff;
  align-items: center;
}

nav {
  background-image: url("header.jpg");
background-position: center;
        padding: 1%;
        overflow: hidden;
 position: absolute;
  left: 0;
  top: 50%; 
  transform: translateY(-50%);
    }

 @media (max-width: 900px) {
   nav { position: static; transform: translateY(0); }
   header { justify-content: space-between; }
 }

    nav a {
        float: left;
        display: block;
        color: orange;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
        font-size 17px;
        font-family: helvetica;
        letter-spacing: 2px;
    }

    nav li, nav ul{
        list-style: none;
    }

    nav a:hover {
        background-color: #ddd;
        color: black;
    }

    nav .material-icons {
        display: none;
        font-size: 36px;
        color: blue;
    }

    @media screen and (max-width: 600px) {
      nav a:not(:first-child) {display: none;}
      nav .material-icons {
        float: left;
        display: block;
      }
    }
htmlcss
<header>

        <nav>
            <i class="material-icons">menu</i>
            <a href="index.html">Home</a>
            <a href="About.html">About</a>
            <a href="Contact.html">Contact</a>
        </nav>
        
        <h1>Knox Enterprises Inc.</h1>

    </header>

Answer №2

You have correctly placed the text and navigation in the header, but for easier manipulation of text positioning using CSS, it should be enclosed within a div, p, or span tag.

To ensure your title remains fixed at the top of the page when scrolling, you can use the position: fixed property. Just remember to apply position: relative to the parent element of the header (e.g., body).

body {
  position: relative;
  padding: 0;
  margin: 0;
}

header {
  position: fixed;
  background-color: #bbc;
  display: flex;
  width: 100vw;
  height: 100px;
  line-height: 50px;
  box-sizing: border-box;
  padding: 0 16px;
  flex-direction: column;
}

main {
  padding: 16px;
  padding-top: 100px;
}

p {
  text-indent: 2em;
<header>
  <span>Knox Enterprises Inc.</span>
  <nav>
    <i class="material-icons">menu</i>
    <a href="index.html">Home</a>
    <a href="About.html">About</a>
    <a href="Contact.html">Contact</a>
  </nav>
</header>
<main>
  <h1>I'm trying to find out a way</h1>
  <p>I'm trying to find a way to integrate my nav bar and header title so they appear cohesive. I want the header text to overlap with the nav bar, both staying fixed at the top of the page as I scroll. I've been experimenting without success, unsure how to modify the HTML and CSS properly.
  </p>
  <p>I'm trying to find a way to integrate my nav bar and header title so they appear cohesive. I want the header text to overlap with the nav bar, both staying fixed at the top of the page as I scroll. I've been experimenting without success, unsure how to modify the HTML and CSS properly.
  </p>
  <p>I'm trying to find a way to integrate my nav bar and header title so they appear cohesive. I want the header text to overlap with the nav bar, both staying fixed at the top of the page as I scroll. I've been experimenting without success, unsure how to modify the HTML and CSS properly.
  </p>
</main>

Answer №3

header>div {
 display:inline;
 float:left
        /*insert something here?*/
    }

    nav {
display:inline;
width:auto;
        background-image: url("header.jpg");
        background-position: center;
        padding: 1%;
        overflow: hidden;
    }

    nav a {
        float: left;
        display: block;
        color: orange;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
        font-size 17px;
        font-family: helvetica;
        letter-spacing: 2px;
    }

    nav li, nav ul{
        list-style: none;
    }

    nav a:hover {
        background-color: #ddd;
        color: black;
    }

    nav .material-icons {
        display: none;
        font-size: 36px;
        color: blue;
    }

    @media screen and (max-width: 600px) {
      nav a:not(:first-child) {display: none;}
      nav .material-icons {
        float: left;
        display: block;
      }
    }
<header>
        <div>Knox Enterprises Inc.</div>

        <nav>
            <i class="material-icons">menu</i>
            <a href="index.html">Home</a>
            <a href="About.html">About</a>
            <a href="Contact.html">Contact</a>
        </nav>

    </header>

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

Retrieving information from the table based on the user currently logged in

I have a scenario with two different tables, NGO and Volunteer. When a volunteer selects an NGO to work with, I want to display only those volunteers who are interested in the current logged-in NGO. Below is the code snippet I am using: [<?php ...

Tips for aligning a textbox and label in the same row with Bootstrap

Is there a way to align two text boxes and a drop-down in the same row while displaying labels below them? I want the layout to look like this: https://i.sstatic.net/eQZnn.png Currently, my code is displaying the text boxes stacked on top of each other. ...

Is it possible to nest Twig variables within other Twig variables?

While developing a website for a reggae backing band, I encountered an issue on the 'booking' page where I have a form. Upon submitting the form, I conduct checks to ensure all required fields are filled in and to verify if any errors occurred. ...

Real-time Exchange of HTML Data Forms

Hey everyone, I am completely new to programming and I would really appreciate your guidance through this process. Let's imagine a scenario where two users need to communicate through HTML forms. The first user fills out an HTML form (first name, la ...

Creating a Bootstrap 4 column form label with a maximum width limit

I am currently working on creating a form within a full-width fluid layout that consists of 2 columns - the label column and the inputs column. The issue I'm running into is that due to the wide screens on fluid layouts, the col-2 label appears too l ...

Discover the best way for child components to utilize parent components' methods in VueJs

I am facing an issue with a button in my parent component that handles form validation. This button triggers the display of a child component, which then makes an API call. The problem arises when I modify the input as the display changes simultaneously. M ...

JavaScript and jQuery experiencing difficulty rendering proper style and image in output display

I am currently working on code that extracts information from a JSON variable and displays it on a map. The code looks like this: marker.info_window_content = place.image + '<br/>' +"<h4>" + place.name + "</h4> ...

Interpret the ng-model data into the input field

My challenge involves translating a value within an input. The input is disabled to prevent users from typing text into the textbox. Currently, the data is entered using ng-model and appears as shown below: <input ng-model="reason" ng-disabled="true" t ...

Using Google Maps within a Bootstrap modal window that is only partially loaded

The maps display perfectly fine in a regular div, but when placed inside a Bootstrap modal, only half or part of the map is visible. However, when I open the console, the issue resolves itself and the entire map is shown. Photo without console opened Pho ...

Issue with changing the height of a textarea in a mobile browser when it is

I'm currently facing an issue specific to mobile devices that I have also encountered on Google Chrome (even when using the developer tools in mobile view). The problem is quite straightforward. There is a simple form on the website, consisting of a ...

Web addresses and the presence of secure HTTP protocol?

Can someone confirm if it is true that when using https, URLs should begin with //[your-domain]/? A friend using WordPress mentioned this but I haven't been able to find specific information on the topic. ...

Fade in text effect using jQuery on a Mac computer

Trying to create a smooth text fading effect across different browsers using jQuery. In the example below, you may notice that during the last part of the animation when the text fades in, the font weight suddenly increases causing a jerky/clunky appearan ...

Incorporate gulp-clean-css into the current gulpfile.js

I was recently provided with a gulpfile.js file by a colleague, which contains the code below. It keeps an eye on my scss files and compiles them when I save. var gulp = require('gulp'), gutil = require('gulp-util'), browser ...

When a class and ID are dynamically applied, the click event may not fire and the CSS may not be applied

Hey everyone, I am facing an issue with declaring id and class when creating a table dynamically. I have tried multiple functions to make my click event work but without success. Can anyone help me with this? Below is the code for my dynamic table where I ...

Achieving an IE7 opacity background while keeping the text unaffected

This is the given HTML code structure (view in JS Fiddle) How can I adjust the background color to be 20% opaque white while keeping the text black? It needs to be compatible with IE7. <ul class="menu"> <li class="first expanded active-trail ...

Generating a vertical line right in the middle of the list item

I have recently designed an HTML page featuring a list of links using ul and li elements, with a customized background color for each li. Now, I am looking to add vertical lines next to the li items. When attempting to insert an image, my output looks lik ...

I'm curious as to why styled components weren't working before

I'm attempting to utilize the before on styled components in React, but it doesn't seem to be functioning correctly. Prior to adding before, the background image was displayed, but after its inclusion, the image is no longer showing up; import st ...

Can we use ToggleClass to animate elements using jQuery?

I have a section on my website where I want to implement an expand feature. I am currently using jQuery's toggleClass function to achieve this effect. jQuery('.menux').click(function() { jQuery(this).toggleClass('is-active&a ...

Incorporating a stationary navigation bar alongside a parallax scrolling layout

After spending the entire night trying to figure this out, I have had zero success so far. I decided to tackle this issue with javascript since my attempts with CSS have been completely fruitless. This is a demonstration of the parallax scrolling webpage. ...

Styling the React Material UI DataGrid with the MuiDataGrid-window class using createMuiTheme or makeStyles / styled-components

I've been putting in a lot of effort to customize the css for the .MuiDataGrid-window in MaterialUi's DataGrid. I've been referencing css rules from https://material-ui.com/api/data-grid/ I managed to get it working within createMuiTheme fo ...