What steps can I take to ensure my header appears perfectly aligned? (HTML/CSS)

My header on my website is all messed up with the links appearing incorrectly. I suspect it's an issue with style.css, so I attempted to modify the style.css file but had no luck. I have very limited experience with .css and cannot seem to figure out how to resolve this problem. Here is an image of my website:

Below is the HTML code snippet:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $page_title; ?></title>   
<link rel="stylesheet" href="includes/style.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="header">
  <h1></h1>
  <h2></h2>
</div>
<div id="navigation">
  <ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="calculator.php">Calculator</a></li>
    <li><a href="lotto.php">Lotto Numbers</a></li>
    <li><a href="craps.php">Craps</a></li>
  </ul>
</div>
<div id="content"><!-- Start of the page-specific content. -->
<!-- Script 3.2 - header.html -->

And here is the CSS code excerpt:

/*
Author  :   Christopher Robinson
Email       :   <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d3e352f342e29322d35382f1d38393a6e733e32732836">[email protected]</a>
Website :   http://www.edg3.co.uk/
*/
* {
   border: 0;
   margin: 0;
   padding: 0;
}
/* general */
a {
   color: #777;
   text-decoration: none;
}
a:hover {
   color: #333;
   text-decoration: none;
}
/* body */
body {
   background: #ffffff;
   color: #555;
   font: 0.8em Arial, Helvetica, "bitstream vera sans", sans-serif;
}
/* header */
#header {
   border-bottom: 1px solid #999;
   height: 80px;
   margin: 0 auto;
   width: 751px;
}
#header h1 {
   color: #888;
   font-size: 300%;
   letter-spacing: -3px;
   text-align: right;
   padding: 5px;
   margin-bottom: -20px;
}
#header h2 {
   color: #CCC;
   font-size: 200%;
   letter-spacing: -2px;
   text-align: right;
}
/* navigation */
#navigation {
   background: #fafafa;
   border-right: 1px solid #999;
   margin: 0 auto;
   width: 750px;
   height: 40px;
   list-style: none;
}
#navigation li {
   border-left: 1px solid #999;
   float: left;
   width: 187px;
   list-style: none;
}
#navigation a {
   color: #555;
   display: block;
   line-height: 40px;
   text-align: center;
}
#navigation a:hover {
   background: #e3e3e3;
   color: #555;
}
#navigation .active {
   background: #e3e3e3;
   color: #777;
}
/* content */
#content {
   height: auto;
   margin: 0 auto;
   padding: 0 0 20px;
   width: 751px;
}
#content h1 {
   border-bottom: 1px dashed #999;
   font-size: 1.8em;
   padding: 20px 0 0;
}
#content p {
   padding: 20px 20px 0;
}

/* footer */
#footer {
   border-top: 1px solid #999; 
   height: 50px;
   margin: 0 auto;
   padding: 10px;
   text-align: center;
   width: 751px;
}
/* Added by Larry Ullman: */
.error, .ad {
   font-weight: bold;
   color: #C00
}
input, select, .input {
   padding: 5px;
   font-weight: bold;
   font-size: 1em;
   color: #008040;
   background: #FFFFFF;
   border: 1px dotted #004080;
}

I tried integrating your code into my file but it didn't solve the issue. The fourth link seems to be causing the problem and I can't seem to fix it.

Answer №1

After reviewing your code on a fiddle at the link: http://jsfiddle.net/QWdy3/, it seems that your navigation items are not fitting correctly within the container. This issue is caused by the padding border applied to the ul for the li elements.

To address this, let's make some adjustments by reducing the element sizes and removing the padding:

#navigation ul {padding-left:0;}
#navigation li {
   border-left: 1px solid #999;
   float: left;
   width: 185px;
   list-style: none;
}

You can see the updated version here: http://jsfiddle.net/QWdy3/1/

It looks like this solution aligns with your desired outcome.

Answer №2

Locate #navigation within your style.css file and include the following:

text-align: center;

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 on how to ensure the navigation menu is the same size as its child elements in the navigation menu

I'm currently designing a navigation menu that includes a child navigation menu. My goal is to have the size of the main navigation menu match that of the child navigation menu. To achieve this, I've created three hyperlink tags followed by a di ...

Image Handpicked by JCrop User

Successfully implemented JCrop example code for selecting an area on an image with a preview and getting coordinates. However, the challenge lies in allowing users to select an image from their file system, display it in the browser, and perform the afore ...

Display an echo within a DIV

Encountering a frustrating issue and seeking assistance. The problem seems to involve loading a page into a DIV. I've created a form for updating database information in a single file with PHP code, loaded into a DIV. When accessing the page directly ...

Guide to pinpointing a location with Google Maps

I am currently working on setting up a contact page that includes Google Maps to show the location of a meeting place. Here is the code I am using: JavaScript (function(){ document.getElementById('map_canvas').style.display="block"; var ...

I would like my division to split into two halves, each with a width of 50%, and be aligned next to each other using fxLayout

<div fxLayout="row" fxLayoutAlign="space-between" style="background-color: blue;"> <div fxLayout="column" style="width: 50%;">1stOne </div> <div fxLayout="column" styl ...

What is the process of displaying text within a link?

I have a basic webpage where I want the text to display from a link. Here is my website: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Encyclopedia</title> <link href="test.css" re ...

Web server experiencing issues with loading scripts and CSS files

After successfully building my project using CodeIgniter on localhost, I encountered an issue when trying to run it on a webhost. The site was functional but the design elements such as scripts and stylesheets were not loading properly. Before uploading t ...

Navigating with Vue Router on Internet Information Services (IIS)

I am encountering difficulties understanding why my routes are failing when I refresh my VueJS application hosted on IIS. Everything works fine during normal browsing, but once I press F5 or update view information through a button, a 403 error is thrown. ...

Selecting elements using XPath

My goal is to target an i element using the following XPath: //div[contains(text(), "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32565356564153565341725e5d5d1c515d5f">[email protected]</a>")]//parent//i[contains(@c ...

How can the backgroundImage css in react admin <Login /> be replaced using Material-UI?

I have been refering to the following resources: Learn about customizing login page background in React-Admin: Explore themes customization in Material-UI: https://material-ui.com/customization/components/ Instead of using a preset background, I want to ...

I've encountered an issue when attempting to use innerHTML for DOM manipulation

I've been attempting to remove a specific list item <li> from the inner HTML by assigning them proper IDs. However, I'm encountering difficulties in deleting it. How can I delete these list items after clicking on the cross button? Feel fr ...

Angular 17 | Angular Material 17.3.1: Problem encountered with Angular Material form field focus and blur event handling

I attempted to apply (blur) and (focus) effects to my mat-form-field input field, but it seems like they are not working properly on my system. Here is a code snippet that resembles what I am using: html file <form class="example-form"> ...

"Troubleshooting a CSS Bug on a PHP Dynamic Web

I have a PHP web page that is dynamic. localhost/ctd/index.php Everything is working fine, except when I add a forward slash like this: localhost/ctd/index.php/ The CSS does not load. Is this a CSS bug or PHP issue? Here is the full code of index.php: ...

The border bottom effect in Hover.css is malfunctioning when used in the Opera browser

I've implemented a hover effect using hover.css that works perfectly in all browsers except Opera. Surprisingly, the effect only seems to work in Opera when I remove the following properties: -webkit-transform: perspective(1px) translateZ(0); transf ...

Having problems with Javascript and CSS not playing well together?

I have implemented a button from this source, but it does not appear correctly on my page. You can view the screenshot here. It seems like there is a conflict between the saved changes and the CSS. How can I resolve this issue? In addition, I am facing ...

Tips for aligning hyperlinks in the navigation bar using CSS3 and HTML5

Struggling to center the links in the navigation bar has been a challenge. I really want those buttons smack dab in the middle of the header bar, but despite trying everything, they stubbornly remain on the left-hand side. .header { overflow: ...

What is the reasoning behind next.js requiring the use of modular CSS instead of a global stylesheet linked to each page?

I am currently attempting to include a minified link stylesheet created with sass:watch into a particular page of a next.js (13) project. However, upon adding it using the head component, I received this warning: Do not add stylesheets using next/head I ...

What is a clear indication that a <div> is filled with text?

Picture a scenario where a website contains an element that needs to be filled with random text using JavaScript. Once the div is completely filled, it should reset and begin again. It may sound odd, but the question is: how will the JavaScript determine w ...

Unable to detect HTML special characters in the text

In my current task, I am facing the challenge of matching two URLs. One URL is retrieved from a MySQL database, while the other one is sourced from an HTML page. When comparing both URLs as strings using Regex, the result shows match.Success = false. Despi ...

Round Loading Animation in CSS

I spent hours scouring the internet for a solution on how to create basic CSS circle shape loaders, but couldn't find anything straightforward. I am working on a special website project that requires displaying survey results in dynamic percentages th ...