What is the best way to customize the text in the navigation bar at the top of the page

I'm having trouble with the Navigation Bar code in my header. The text is not staying within the header and I can't seem to fix it. Is there a CSS solution to keep the text contained within the header?

<div class="header">
  <img src="img/logo.png" alt="logo" />
  <h1>Empowering The Nation </h1>
</div>
<ul class="navigation">
  <a href="Home.html"><b>Home</b></li></a>
  <a href="Courses.html"><b>Courses</li></b></a>
  <a href="Pricing.html"><b>Pricing</b></li></a>
  <a href="Contact.html"><b>Contact Us</b></li></a>
  <a href="Sign In.html"><button>Sign In</li></button></a>
</ul>
</div>
</div>

Answer №1

Ensuring your HTML is valid is crucial. For instance, eliminating unnecessary closing tags like </div>, ensuring there are opening <li> tags for every closing </li> tag, and so on. To incorporate a navigation bar in the header, simply place your code within the header div. I have made some adjustments and provided an example of what properly formatted HTML looks like.

<!DOCTYPE html>
<html lang="en">
  <header>
    <meta charset="UTF-8" />
    <title>Home</title>
    <link rel="stylesheet" type="text/css" href="Home.css" />
    <div class="header">
      <div class="page-title">
        <img src="img/logo.png" alt="logo" />
        <h1>Empowering The Nation</h1>
      </div>
      <div>
        <ul class="navigation">
          <li><a href="Home.html">Home</a></li>
          <li><a href="Courses.html">Courses</a></li>
          <li><a href="Pricing.html">Pricing</a></li>
          <li><a href="Contact.html">Contact Us</a></li>
          <!--Why this button ?-->
          <li><a href="Sign In.html"><button>Sign In</button></a></li>
        </ul>
      </div>
    </div>
  </header>

  <body>
    <div>This is the body of the page</div>
  </body>
</html>

<style>
  .header {
    display: flex;
    justify-content: space-between;
  }

  .page-title {
    display: flex;
    justify-content: flex-start;
    align-self: center;
  }

  img {
    align-self: center;
  }
</style>

Answer №2

Your HTML code seems to have some errors, but I have made corrections to address the issue. To solve your problem of having a horizontal list, you can utilize flexbox. By applying display: inline to both the unordered list (ul) and list items (li), you can achieve the desired outcome.

Example:

.nav {
  
  display: flex;
  justify-content: space-between;
  gap:20px;
  margin: 0 auto;
}

.navigation {
  display: flex;
  align-items: center;
  justify-content: center;  
}
.navigation ul, li{
  display: inline;
  padding: 0 10px;
  font-weight: bold;
}

.navigation a {
  color: black ;
}
<div class="nav">
  <div class="header">
    <img src="img/logo.png" alt="logo" />
    <h1>Empowering The Nation </h1>
  </div>
  <div class="navigation">
    <ul>
      <li><a href="Home.html">Home</a></li>
      <li><a href="Courses.html">Courses</a></li>
      <li><a href="Pricing.html">Pricing</a></li>
      <li><a href="Contact.html">Contact Us</a></li>
      <li><a href="Sign In.html">Sign In</a></li>
    </ul>
  </div>
</div>

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

Send image data in base64 format to server using AJAX to save

My goal is to store a base64 image on a php server using the webcam-easy library (https://github.com/bensonruan/webcam-easy). I added a button to the index.html file of the demo: <button id="upload" onClick="postData()" style=" ...

Can text automatically adjust its size based on the browser's dimensions using CSS?

Can text automatically resize as the browser size decreases for liquid-based design using percentages? While images and divs can rescale, text scaling in percentages seems impossible! When set in percentages, it only changes the unified em setting for tha ...

Elements that are sortable will remain in place even after being removed from

In my project, I have created a list with sortable elements that can be deleted by dragging them into a trash bin. However, I am facing an issue where the element remains visible even after being removed. <div class="content-remove" id="content-rem ...

The relationship between elements and text input positioning

I am faced with a unique challenge. As a user types in an input field, I need to display a reset button positioned center right of the input. I must adhere to the current HTML structure for the label, input, button, and error message and I prefer not to r ...

Learn how to use CSS flexbox to easily vertically center items within a container with a full-height background

I'm having trouble with aligning text vertically centered within a box and making sure the background color stretches to full height. HTML: <div class="feature-content"> <div class="feature-visual"> <div class="embed-container"> ...

Creating a customized design for a q-popup-edit

As I navigate through using Quasar in Vue, I stumbled upon a q-popup-edit that allows me to gather input from the user. Despite my attempts at researching via Google and reading documentation, I have hit a roadblock when it comes to customizing the style o ...

Can CSS be altered dynamically in Laravel blade?

Is there a way to dynamically change CSS? I am trying to set the class=sheet padding-top: 28mm; when the size of $anArray is less than 30. If the array has more than 30 elements then apply padding-top: 28 * 2 mm;. Finally, if the array exceeds 60, use pad ...

Position the div in the center, but for smaller sizes, switch to aligning

My current layout setup is as follows: Left side bar with a width of 200px and positioned at left: 0; Center section with a width of 700px and positioned at left: 250px; Right side bar with a width of 200px and positioned at right: 10px; While this arra ...

What is the best way to alter the background-color of an element that is contained within a GatsbyJS component, depending on the specific page where the component is being utilized?

As a first-time GatsbyJS website builder, I am working on creating reusable components for my site. One of these components is the footer, and I have already structured it. Now, I have a dilemma - I want to change the color of a specific <div> within ...

Exploring Font Choices: Customizing Your Text Style

I've been attempting to incorporate my own font into my website, but despite researching several Stack Overflow articles, I'm facing various browser-specific and path-related issues. Sadly, I haven't been able to successfully display my font ...

How can a JavaScript function be used to check a tag's status?

I currently have two select tags on my webpage. I want to ensure that only one option can be selected at a time from these two tags. If the user tries to select options from both tags, an error message should be displayed instructing them to choose only on ...

In Chrome, CSS automatic hyphens are displayed as question mark symbols

On my website, I have implemented automatic hyphenation using CSS: article > p, article > li { -o-hyphens: auto; -o-hyphenate-limit-before: 3; -o-hyphenate-limit-after: 3; -o-hyphenate-limit-chars: 6 3 3; -o-hyphenate-limit-lines: 2; -o-h ...

The implementation of modal pop-ups is resulting in unresponsive touch areas on mobile devices and tablets

I recently finished putting together a one-page website using Twitter Bootstrap, based on a theme from Themeforest that I heavily customized. However, when viewing the site on a mobile or tablet, I noticed an issue where the top 2/3 of the page is unrespon ...

What is the method to display just the final 3 characters within a paragraph?

Is there a way to display only the last three characters of a string using either a method or a string method? I consistently have a 13-digit number, but I specifically require showing only the final three digits. Appreciate any assistance provided. Than ...

Is there a way to display one of the divs in sequence each time the page is reloaded?

Is there a way to display the divs sequentially when the page is refreshed? For instance, on the initial load, only div 1 should appear, and with each refresh it should cycle through divs 2, 3, 4, and 5 before starting over. Below is an example I'm c ...

Are there any methods to improve the coding, align images to the center, and ensure that elements stay in their designated positions?

Is there a way to tidy up the code, center images, and keep everything in place? This is the look I desire: The main outer box should remain centered on the browser page. Pause, play, and stop buttons should float to the left of the box. My image sh ...

Manipulating parent based on first child using CSS

Is it possible to manipulate the parent element using CSS based on the presence of a specific child? For instance, I want to style a table cell differently if the first child within it is a link. <td>Hello</td> <td><a href="go.html"& ...

Arrange the table by adding and editing before and after appending

I have a table data that needs to be dynamically appended. But I want to allow users to add new data using text input and also edit the existing data before and after it's appended. The problem is that when I append new data, it overwrites the previo ...

"Displaying mongoose date in the HTML5 input type date format (dd/mm/yyyy) is a simple process that can

I have a structured data in MongoDB as shown below: var Person = new Schema({ "Name": { type: String, required: true }, "DOB": { type: Date, "default": Date.now } }); An instance of this schema is created using NodeJs with mongoose ODM: { "N ...

Using Rails to assign a page-specific CSS class within a shared layout

Is there a way to apply unique CSS classes to specific tags within a common layout? In my application.html.erb layout file, the application.css.scss is loaded using <%= stylesheet_link_tag "application". . . %>, which then includes all CSS files in ...