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

AngularJS: Solving the issue of controllers not exchanging data by utilizing a service

I am working with the following controllers and service: angular.module('myApp', []); angular.module('myApp').factory('ShareService', function() { var information = {}; information.data = ""; information.setD ...

Parent div's overflow due to its flexbox properties

I am currently facing a dilemma with my nested flexbox setup. The primary objective is to create two responsive columns: .ColWrap, { width: 100%; box-sizing: border-box; background-color: #fff; padding: 50px 10px 50px 25px; display: fl ...

Problem with the mobile site width due to viewport misalignment

Our website is currently experiencing an issue with the viewport, but it seems to only occur on mobile devices: If you visit the site on your mobile device, you may notice a large gap on the right side of the page. Strangely, this problem does not appear ...

What is the best way to allocate a unique color to every item within an array?

I've been working on some JavaScript code that pulls a random color from a selection: const colors = [blue[800], green[500], orange[500], purple[800], red[800]]; const color = colors[Math.floor(Math.random() * colors.length)]; Within my JSX code, I ...

Exploring the use of dictionaries within Django templates

views.py: return render(request,'images.html',temp) Temp Data: {'cluster1': ['temp/vinoth/cluster1/demo-pic94.jpg', 'temp/vinoth/cluster1/id1.jpg'], 'cluster2': ['temp/vinoth/cluster2/demo-pic94.jp ...

Bizarre Incident Management

My latest project involves a simplistic website featuring arrow images (png) positioned on the left and right sides with fixed placement, allowing users to navigate to the next page. However, an issue arises where the cursor seems unable to select the an ...

Strategies for limiting a table row in JavaScript or jQuery without utilizing the style tag or class attribute for that specific row

I am looking for a way to limit the display of records in a table. Currently, I can restrict the table rows using the style property, but this causes UI issues such as missing mouse-over effects for the entire row. I need to ensure that mouse-over functi ...

What is the best way to dynamically update form fields in a database after making a selection in a <select> component?

Currently, I have a form that displays a list of stars (stellar objects) with a <select> control and two <inputs>. I am seeking guidance on how to populate the two inputs from the database when the user changes the selection in the <select&g ...

Tips for aligning sections of a navigation bar in different directions: left and right

I'm attempting to float a logo to the left side of a nav bar and have the text float to the right of the nav bar using Bootstrap. I've tried adding float and text align classes to outer divs and specific elements but haven't had success yet. ...

Extract the raw text content from nested elements

Working with highlight.js to include a custom CSS code, however, this library automatically adds span tags around the desired text For example: <pre> <code class="language-css hljs" contenteditable="true" id="css-code&quo ...

Tips for using jQuery to identify the most recently modified row in an HTML table

Is there a way to identify the most recently modified (either newly added or changed) row in an HTML table? ...

Is there a way to modify the video height so that it aligns with the dimensions of the

I'm currently trying to adjust the background video to fit the parent div, but I am facing issues with adjusting its height within the media query. Any suggestions on how I can resolve this problem? HTML <div class="hero"> <video ...

Request financial data from AlphaVantage using PHP

I'm currently working on utilizing the alphavantage API to retrieve currency exchange information. In order to obtain the desired data, I am using the following query URI: https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_cu ...

Creating a stylish CSS shadow effect for a collection of elements

In my Ionic2 project, I have an <ion-list> consisting of various items. Currently, these items are plain, but I desire to add some styling such that each item in the list displays a subtle shadow effect, similar to the one shown in the first image of ...

What is the proper location to place the CSS I wish to implement for a module?

As I embark on creating my inaugural DotNetNuke website, I find myself faced with the task of adding an HTML module to a page. To style the text within it, I have been advised to utilize CSS classes. I'm curious about where .css files should be place ...

Adjusting the image height to match the container height while preserving its original aspect ratio

Is there a method, using CSS alone, to adjust an image's height to fit its container while preserving aspect ratio and allowing the overflow of width to be concealed? It may seem like a complex set of requirements, but is it achievable? Essentially, I ...

Creating a Stroke on an html5 canvas with the help of EaselJS

As a newcomer to Easel and HTML5, I am attempting to draw a line on a canvas using EaselJS. The X-coordinate is set to 100 while the Y-coordinate is taken from an array list. Below is the code I have written. Can someone please help me identify where my ...

Adjusting image dimensions before delivery for a mobile site

On my desktop website, I currently use images with a size of 500*500. However, when it comes to the mobile version of my site, downloading such large images takes an excessive amount of time. Simply specifying width & height attributes in <img> doesn ...

Mastering the art of incorporating background image transitions and creating a seamless slider for navigation

Is there a way to create a navigation menu like the one on this theme? On this theme, when you hover over a menu item, the background image smoothly moves left or right to the item you are hovering on. If anyone knows of plugins that can achieve this eff ...

What's the best way to display a component once a function has been executed?

My service controls the visibility of components using *ngIf! Currently, when I click a button, the service sets to true and the components appear instantly! I want the components to only show after a specific function has finished executing. This means I ...