Seeking assistance with organizing a navigation bar in html and CSS

Just starting out with HTML and CSS and working on creating a website. I'm starting with the navbar, but I'm facing an issue with scaling for different screen sizes. In full screen, it looks fine, but when minimized, the "About" part on the right side doesn't load. Currently, all menus point to the same page, which is my current objective.

Here's the Code:

body {}

.navbardiv {}

.navbar_ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  /*overflow:hidden;*/
  background-color: #333;
  border: 5px solid gray;
  margin: -8px;
  width: auto;
  min-width: 600px;
  height: 70px;
}

li {
  float: left;
  padding: 10px 150px;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px 16px;
  text-decoration: none;
}

li a:hover {
  background-color: #111;
}
<!--NAVBAR-->
<div class="navbardiv">
  <ul class="navbar_ul">
    <li class="navbar_li_Contact"><a href="index.html">Contact</a></li>
    <li class="navbar_li_WebHosting"><a href="index.html">Webhosting</a></li>
    <li class="navbar_li_About"><a href="index.html">About</a></li>
  </ul>
</div>

Answer №1

The padding for the li elements is currently set to 150px, which is excessively high. It is recommended to reduce this value for better design.

However, if you prefer the links to occupy the entire width and be evenly spaced, you can utilize flexbox and apply justify-content: space-between; to achieve this layout.

Check out the code snippet below for reference:

body {}

.navbardiv {}

.navbar_ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  background-color: #333;
  border: 5px solid gray;
  margin: -8px;
  width: auto;
  min-width: 600px;
  height: 70px;
  display: flex;
  justify-content: space-between;
}

li {
  float: left;
  padding: 10px 20px;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px 16px;
  text-decoration: none;
}

li a:hover {
  background-color: #111;
}
<!--NAVBAR-->
<div class="navbardiv">
  <ul class="navbar_ul">
    <li class="navbar_li_Contact"><a href="index.html">Contact</a></li>
    <li class="navbar_li_WebHosting"><a href="index.html">Webhosting</a></li>
    <li class="navbar_li_About"><a href="index.html">About</a></li>
  </ul>
</div>

Answer №2

Your navigation menu isn't adapting properly to different screen sizes due to the min-width: 600px; rule. This code ensures that the menu stays at a minimum width of 600px even on smaller screens, causing it to align to the left side and cut off the right edge. Using min-width: 100%; also won't solve the issue because it will crop the menu when the inner elements exceed the available space.

The solution is simple - just update it to width: 100%;.

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

What is the best method for calculating the total of a column field within an array in Angular 9.1.9?

I am using Angular 9.1.9 and Html to work with a nested array field in order to calculate the total sum and display it in a row. Within my array list ('adherant'), I am aiming to sum up a specific column's values ({{ Total Amount }}) and pr ...

The Ajax load() function is malfunctioning

.load() will only function properly when the files are coming from a server, so I anticipate that it will work later once I have it hosted on a server Edit: This code is functional in Firefox but not in Chrome I've been attempting to apply ajax to l ...

Which is better to use: sql==true or sql===true?

Hey there, could you please take a look at this and thanks in advance! I'm currently working on developing a system for upgrading buildings in my game. I have set up a universal upgrade div that applies to all buildings. When the player clicks on a bu ...

Hovering over the Star Rating component will cause all previous stars to be filled

I'm in the process of creating a Star Rating component for our website using Angular 11. I've managed to render the 5 stars based on the current rating value, but I'm having trouble getting the hover styling just right. Basically, if I have ...

I am interested in modifying the destination of the screen transition depending on the numerical input provided in the form

I have recently started working on a project using Spring Boot, Thymeleaf, and MySQL. For instance, when the input form is submitted with the value "1" as the DB ID, I expect to be redirected to http://localhost:8080/edit/1. However, I am facing an issue ...

Tips for keeping a reading item in place while scrolling

To enhance the user experience, I would like to improve readability without affecting the scroll position. Question: Is there a way to fix the scrolling item at a specific position (item with the .active class)? I am looking to maintain a consistent read ...

What is the proper method for storing user registration information in the database so that it can be easily retrieved and accessed later? (Error message)

User.cs: An error is occurring in the User class where 'User' is not a valid type in the context of TestBlazor project. It happened when attempting to save user registration data. using System; using System.Collections.Generic; using S ...

Arranging elements within distinct div containers

Utilizing Bootstrap 4, I crafted a card-deck containing two cards. Despite the equal height of both cards, the alignment of elements is affected by varying text lengths. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min ...

Complete the form by following a hyperlink located on a different webpage

I recently developed three PHP pages. The first one consists of the following form: <form method="POST" name="go" action="search_form_all.php" > <input name="value" type="text" id="search_form_1" size="65" placeholder="enter name"/> <i ...

Utilizing CSS Grid to dynamically stretch and wrap rows based on adjacent siblings within a flat DOM structure

Looking for a way to create a grid layout that adjusts row sizes based on adjacent siblings. Interested in SCSS or CSS solutions using grid, flexbox, or other techniques. https://i.sstatic.net/Ump5U.png I am working with a dynamically generated list base ...

Identify Bootstrap modal to modify destination of keypress input

I am working on a piece of code that detects keypress events and focuses input towards a searchbar with the id "search". $( document ).keypress(function() { $("#search").focus(); In addition, I have a bootstrap modal dialog containing input fields ...

Is it possible to use v-if in conjunction with a style tag to specify a different source file? Alternatively, is there a more efficient method I

I attempted the example provided below, but unfortunately, it did not function as expected. The reason behind my endeavor is that adding numerous modifiers (--tuned) to achieve the desired outcome seemed impractical. Therefore, I decided to try and link ...

Fixed Row Feature in Visual Composer

Currently, as I work on a website in Wordpress utilizing the Visual Composer page builder, I have encountered a dilemma. I am attempting to ensure a row remains sticky at the top of the page. In an effort to achieve this, I have inserted the following CSS ...

Having trouble triggering drag events efficiently with d3-drag on SVG elements

drawAll refers to a two-dimensional array where each drawAll[i] element represents a drawing containing all the strokes. A stroke is essentially a string representing a series of 2D points that can be utilized to generate a <path>. I am currently at ...

Declare React component as a variable

I'm facing a simple issue that I need to solve. After creating a React app using npx create-react-app, I designed a Map component which I integrated into my view with the following code: class App extends Component { render() { return ( ...

What is the best way to make a div that maintains its size even when the content inside is modified?

My goal is to develop a media feed that includes various types of content such as text, images, and videos. To ensure user safety, I want to conceal any explicit posts with a warning that requires the user to click in order to view the content. Although I ...

Verifying StartDate and EndDate using AngularJS and Bootstrap Datepicker

My HTML Coding <form name="myForm"> <div class="row"> <div class="col-md-2"> <input data-ng-model="Data.StartDate" type="text" id="startDate" name="startDate" class="form-control" data-da ...

The Sticky Navigation Bar Disappears After a Certain Scroll Point

Looking for some help with my website's navbar - it works fine until I scroll past the blue section, then it disappears along with other elements. Any suggestions on how to fix this? Thanks! <!DOCTYPE html> <html lang="en"> <h ...

script to pause video using jQuery

I have a script that works perfectly, but currently it only stops an instance of a playing video if a new video is started. I want to modify the script so that ALL instances of playing videos are stopped when the function stopAllButMe(); is called. Can s ...

Concatenating strings with JavaScript

I am currently working on building a web page using a combination of html and javascript. I have a json file that provides inputs for some specific content I need to display. My main goal is to set up an address variable in order to show the Google Maps AP ...