Floating elements are not aligned to the left

So, I've set up this 139px height header in Dreamweaver, but when I preview it in a browser, the menu div splits onto a second row. Can anyone help me fix this issue?

This is the HTML structure:

<div id="header">
    <div id="header2">
        <div id="title">
            <a href="index.html"><img src="titleimg.png" border="0" /></a>
        </div>
        <div id="menu">
        <div id="one"></div>
            <div id="two"></div>
            <div id="three"></div>
            <div id="four"></div>
            <div id="five"></div>
        </div>
   </div>
</div>

And here's the CSS styling:

#header {
    top: 0;
    left: 0;
    position: fixed;
    height: 139px;
    width: 100%;
    background-image: url('headerbg.png');
    border-bottom: solid 1px #797978;
    text-align: center;
    display: inline-table;
}
#header2 {
    width: 1040px;
    margin: 0 auto;
    text-align: left;
}
#title {
    padding-top: 27px;
    width: 287px;
    height: 112px;
    background-image: url('title3d.png');
    background-repeat: no-repeat;
    background-position: right bottom;
    float: left;
}
#menu {
    width: 753px;
    height: 13px;
    border-left: solid 1px #474747;
    display: inline-table;
}
#one, #two, #three, #four, #five {
    width: 19%;
    height: 139px;
    border-right: solid 1px #474747;
    float: left;
}

If you have any suggestions or solutions, please let me know. Your help is greatly appreciated!

Answer №1

Don't forget to consider the 1px border on your #menu when calculating the total width of 1040px that's causing an overflow issue. Adjusting the widths of either #menu or #title by 1px will resolve it :)

To optimize your code, you can use a single rule for all #menu elements such as #one, #two, etc:

#menu > div {
    width:19%;
    height:139px;
    border-right: solid 1px #474747;
    float:left;
}

Answer №2

Your title element's width has been defined as 287px; which exceeds the size of its container.

Answer №3

I made some adjustments to your code in order to improve its functionality.

http://jsfiddle.net/lyFdr/

The main issue you're encountering is that the combined width of #title and #menu exceeds 1040px, which is the width of your header. This oversight is due to not accounting for borders on the siblings within #menu.

I also recommend using classes for consistent styling across different elements. Feel free to let me know if there's anything else I can do to enhance my solution with improved code.

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

How can jQuery be used to adjust the width and height of an iframe?

After researching a solution on a website, I attempted to implement it but encountered issues. It seems like there may be another script dictating the styling, so I need to add some code directly to the page to override it. This is what I tried: <scri ...

Why are the elements not aligned in a single row?

Can anyone explain why these two elements are not displaying on the same row when using Bootstrap 4? <div class="container"> <div class="row"> <div class="col-lg-2"> <a class="logo"><img class="logo__img" src= ...

CakePHP: Explaining the contrast between " $this->fetch('css') and $this->Html->css('cake.generic')" when working with CakePHP

Could anyone provide a brief explanation of these two lines found in the CakePHP layout.ctp file? It appears that both lines are used for adding CSS. What is the distinction between them? How do they function? $this->Html->css('cake.generic&ap ...

Stopping tabbing to elements outside of the Angular-UI Bootstrap modal window: A guide

When using Angular-UI Bootstrap to open a modal, I noticed that when pressing the 'tab' key to cycle through elements within the modal window, it sometimes starts selecting elements that are behind the modal itself. If you want to see this in ac ...

What is the best way to update all outdated images by replacing them with new ones using node.js?

I am not looking for a way to replace all broken images with default images, as that question has already been answered here. My inquiry is regarding how to replace all broken images with newly updated ones. In my web chat application, users have the abil ...

Transitioning to mui5's sx prop instead of makeStyles is generating a typescript error - none of the overloads match this call when passing an object with

I encountered an issue while converting a component to mui 5. Here is the original code snippet: const useStyles = makeStyles({ imageContainer: { display: "flex", width: "65%", float: "left", marginRight ...

Avoid activating the hover effect on an element situated below another element without the use of JavaScript

After reviewing various posts, it seems like the only solution involves using javascript. Is there a way to hover over one element without affecting the style of another element below it, all without relying on javascript? I'm looking for a solution u ...

Coloring a table in vue.js based on performance rankings

I'm facing an issue with sorting my data performance in vue js. Here is the script I have created so far: <template> <div> <div class="row"> <h2> Campaign Performance </h2> <table class=&q ...

Show content based on information from an array using JavaScript

I am currently working on developing a user-friendly step-by-step form using AngularJS and UI-router to navigate through different sections. The data collected from each form is stored in a JavaScript array, and I am trying to dynamically show or hide a di ...

Troubleshooting a Hover Problem in Firefox

Chrome is rendering the following code perfectly fine, but Firefox seems to be having trouble applying the hover effect. HTML <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> ...

Disabling the submit button prevents the form from being submitted

After coming across this code designed to prevent double submission of a form, I noticed that it is not functioning correctly. Despite disabling the submit button and changing its value to "Please wait", the form is still being submitted. <input type=" ...

Adjusting the mouse movement update frequency – what you need to know!

As I work on developing a function that requires a quick and easy signature, I am facing an issue with the canvas field. Despite using jQuery to handle the signature, the refresh rate of mousemove coordinates seems too slow. This results in white spaces be ...

Troubleshooting issues with Bootstrap Nav-pills functionality

I have encountered an issue with my navigation structure. I am using a main nav-menu and a secondary nav-menu within the same div. When I first enter the page, the "Profile" tab is correctly active by default. Then, when I click on "Test", it becomes activ ...

Creating a custom design for a dropdown menu in the Bootstrap navbar

My Bootstrap navbar has a unique color scheme for the navbar itself and the letters, as indicated in the following CSS: .jumbotron { background-color:#2d4c60 !important; } nav.navbar { background-color: #2d4c60; } .nav.navbar-nav.navbar-ri ...

The NextJS Link component does not seem to be receiving the styles from Tailwindcss

I am currently working on a nextjs frontend project that has tailwindcss integrated. Below is an example of the code I am using: import Link from 'next/link' return( <div> <Link className="text-sm hover:text-gray-600" ...

Achieving optimal performance with scoped CSS in Vue.js

As I work on creating a new app using VueJs, I have noticed the implementation of "css scoped" as shown below: <style scoped> .example { color: red; } </style> <template> <div class="example">hi</div> </template> ...

Preventing a div from receiving click events

I'm facing a challenge with what I thought would be a simple task. Within my parent div, there are multiple child divs each with onclick events attached to them. Now, when the page is loading data asynchronously through an ajax call, I need to preven ...

All fields in the form are showing the same error message during validation

This is the HTML code: The form below consists of two fields, firstname and lastname. Validation Form <form action="" method="post"> Firstname : <input type="text" placeholder="first name" class="fname" name="fname" /> <span class= ...

Show various attachment file names using jQuery

Utilizing jQuery, I've implemented a script to extract the filename from a hidden field and then append it to the filename class in my HTML. filenameCache = $('#example-marketing-material-file-cache').val().replace(/^.*[\\\/ ...

The layout of my website appears distorted on mobile devices

When I view my website, http://www.healthot.com, on an iPhone or other mobile device, the page doesn't display correctly. It scales the window, requiring me to zoom out to see the entire page. To better understand the issue, please refer to this photo ...