What is the best way to insert a header immediately following a navigation bar using HTML and CSS?

I've been attempting to insert a basic text header right after a navbar on the same line (at the very top of the webpage) but I can't seem to find a way to keep them side by side.

Check out the code below: CSS:

.navbar div {
    display: block;
    height: 5px;
    background: #fff;
    float: left;
    margin: 7px 0px 7px 0px;
    transition: all 0.5s;
    -webkit-transition: all 0.5s;}
.one {width: 40px;}
.two { width: 30px;}
.three { width: 25px;}
.navbar:hover div { width: 40px;}

.header {
    display: flex;
    justify-content: center;
    width: 100%;
    float: right;
    align-items: center;
    color: gold;}

HTML:

<div>
<nav class="dropdown">
    <ul>
    <li>
    <a href="index.html" target="_blank" class="navbar">
        <div class="one"></div>
        <div class="two"></div>
        <div class="three"></div>
    </a>
        <ul>
          <li><a href="#">Experience</a></li>
          <li><a href="#">Skills</a></li>
          <li><a href="#">Socials</a></li>
        </ul>
    </li>
    </ul>
</nav>
<h1 class = "header">Sam Jenkins</h1>
</div>

I attempted to wrap the header and navbar inside a div tag while setting the navbar to float left and the header to float right.

Answer №1

It seems like you are attempting to use flexbox properties directly on the header itself, but these should actually be applied to a parent container.

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar div {
  height: 5px;
  background: #fff;
  float: left;
  margin: 7px 0;
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}

.one {width: 40px}
.two {width: 30px}
.three {width: 25px}
.navbar:hover div {width: 40px}

.header {
  color: gold;
}
<header>
  <nav class="dropdown">
    <ul>
      <li>
        <a href="index.html" target="_blank" class="navbar">
          <div class="one"></div>
          <div class="two"></div>
          <div class="three"></div>
        </a>
        <ul>
          <li><a href="#">Experience</a></li>
          <li><a href="#">Skills</a></li>
          <li><a href="#">Socials</a></li>
        </ul>
      </li>
    </ul>
  </nav>

  <h1 class="header">Sam Jenkins</h1>
</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

Update a variety of CSS properties simultaneously

Is it possible to change multiple CSS attributes of an element with just one line of code? Currently, if I want to alter various CSS attributes of an element, I have to write separate lines of code for each attribute. For instance: $("div#start").cli ...

What could be causing my table to malfunction in IE8?

Is it just me, or do my CSS tables not work on IE8? <div class="main-table"> <div class="row"> <a class="secondary-table" href="#"> <div class="secondary-row"> <div class="secondary-cell"> ...

The validation process using jQuery may encounter errors when attempting to validate inputs before an 'require_from_group_exact' input

Utilizing the jQuery Validation Plugin, I am able to validate various inputs on an HTML page. It is necessary for the first name to always be provided, and either an email OR a mobile number but not both. This validation is achieved by using the require_fr ...

Scraping using Regex to extract form_ids with varying values but identical names

Is there a way to extract the value of a form id from an HTML page using either regex or xpath, specifically focusing on scraping the value from the second instance of the form_id name? Any suggestions on the most effective method to accomplish this using ...

The PDF generated by HTML2PDF does not accurately represent true CMYK black with values of 0% cyan, 0% magenta,

I am currently using HTML2PDF to create a PDF document from text entered into a textarea and an image uploaded by the user. The CSS styling is set up using a style block, which is working well as the resulting PDF looks exactly how I want it to. However, ...

How can the Bootstrap Jumbotron element be adjusted to perfectly fill the width of the screen?

Currently, I'm utilizing a jumbotron element on my website and aiming to make it fluid in order to adapt and fit the entire jumbotron to the screen width. However, I seem to be facing difficulty when attempting to increase its width. Below is the cod ...

Clicking to center div elements

When clicking on my div elements, they transform into flipcards and expand to a size of 600px by 600px. I want these divs to be centered in the middle of the screen when clicked, and then move back to their original position when clicked again. I've b ...

Learn how to implement a feature in your chat application that allows users to reply to specific messages, similar to Skype or WhatsApp, using

I am currently working on creating a chatbox for both mobile and desktop websites. However, I have encountered an obstacle in implementing a specific message reply feature similar to Skype and WhatsApp. In this feature, the user can click on the reply butt ...

What is the best way to preserve code in a blog post without any alterations to the code itself?

@"//div[@id='transcriptText']/div[@class='notranslate']/p/a/@href"]; @"//div[@id='videoPlayerSWF']/noscript/div/p/a/@href"]; @"//div[@id='transcriptText']/div/p/a/text()"]; @"//div[@id='transcriptT ...

Database table entry form

I'm attempting to create a form that sends the index.php input to my database table using index.php and connection.php. I also want to set everything else to be in letter format except for the phone number (puhelinnumero), which should be in numeric f ...

AngularJS Bidirectional binding in a directive

Situation: I am facing an issue with a controller that manages an array of player stats and displays them to the user. Each player has a set of stats that can be adjusted by the user. To simplify this process across different stats, I am developing a direc ...

<header data-profile="http://gmpg.org/xfn/11">can anyone explain this to me?

I received this code snippet from a WordPress site. <head profile="http://gmpg.org/xfn/11"> Can someone explain what this code does? What is the purpose of including this code? :-) ...

Animating with JavaScript

I have a members button on my website that triggers a dropdown animation when clicked. However, the issue is that the animation occurs every time a page is loaded, even if the button is not clicked. I want the dropdown to only open when the button is click ...

Using the rvest package to extract data from a password-protected website without the need to log in every time the loop iter

My goal is to extract data from a password-protected website using the rvest package in R. Currently, my code logs in to the website in each iteration of a loop, which will be repeated approximately 15,000 times. This approach seems inefficient, but I have ...

Is there a way to wrap the "#+ATTR_HTML" tags around the preview output of the "#+RESULTS" Source Block in Org-mode for Emacs?

Using plantuml in org works fine for me. However, I am looking to enhance it by automatically inserting some HTML tags just before the #+RESULTS output tag. This will help achieve a more visually appealing HTML output effect. Here's an example of my ...

What is the process of enabling scrolling on the main panel once scrolling on the sidebar has concluded?

How can I achieve a scrolling behavior similar to the one demonstrated here? When scrolling through the sidebar, I want it to continue scrolling until it reaches the end. After that, any further scrolling on the sidebar should scroll the main panel inste ...

Having trouble setting up a page layout with CSS grid or grid-template-areas

Hey everyone, I'm a beginner in the world of HTML, CSS, and JS and this is my first time reaching out for help. I've been searching through various forums and spending quite some time on this particular issue, but unfortunately, I haven't fo ...

Alignment issue with Bootstrap navbar hamburger icon in vertical positioning

I am currently utilizing fluent kit with bootstrap version 4.1.2. After referring to the navbar documentation (specifically interested in the toggler that changes its icon when opened/closed), I chose the second example from the #position section. However ...

Issue with CSS styles (td and p elements) not being applied in emails sent from MS Outlook through Gmail Android & iOS App

My email is sending perfectly from MS Outlook (2013), but in the GMail app for Android (also happening on iOS) there seems to be an unwanted gap between lines. It's known that MS Outlook changes the HTML upon sending the email, which can be viewed by ...

Trying to arrange HTML elements in a diagonal configuration while ensuring they are all uniform in size

My goal is to create an attractive splash page with diagonal, circular links that are all the same size. The <p>'s will function as the links, but I'm struggling to figure out how to make them all diagonal and uniform in size. I've ex ...