What could be causing the DIV to be out of place when the window is resized?

When the window is minimized, all elements remain intact except for the navigation.

https://i.sstatic.net/xewNu.jpg

The image below shows the layout when the window is maximized, while the image above depicts the layout when the window is minimized.

HTML:

<header>
    <div class="header">
        <div class="logo">
            <img src="images/logo.png" />
        </div>

        <nav>
          <div class="navigation">

                <a href="home.html">
                    <div class="box" style="background: rgba(0, 0, 0, 0.4)">
                        <img src="images/home.png">
                     <div class="name" style="background: rgba(0, 0, 0, 0.4)">HOME</div>
                    </div>
                </a>

                <div class="box">
                    <img src="images/aboutus.png">
                    <div class="name">ABOUT US</div>
                </div>
                <div class="box">
                    <img src="images/groupcompanies.png">
                    <div class="name">GROUP OF COMPANIES</div>
                </div>
                <div class="box">
                    <img src="images/career.png">
                    <div class="name">CAREER</div>
                </div>
                <div class="box">
                    <img src="images/contactus.png">
                    <div class="name">CONTACT US</div>
                </div>

            </div>
        </nav>
    </div>    

</header>

CSS:

body {
    background-image:url(images/pattern.png);
    min-width: 775px;
    overflow:auto;
}

@font-face {
    font-family:"myfont";
    src:url(font/PTN57F.woff);
}
.header {
    max-width:1200px;
    min-width:200px;
    height:170px;
    margin:0 auto;
    margin-top:10px;
    background-color:rgba(0, 0, 0, 0.5);
    border-radius:3px;

}

.logo {
    width:230px;
}

.logo img {
    margin-left:20px;
    margin-top:31px;
    border-right:solid  #FFF 1px;
    padding-right:33px;
    height:auto;
    width:auto;
    float:left;
}


.navigation {
    width:800px;
    height:100px;
    margin-left:256px;
    float:none;

}

.box {
    height:100px;
    width:150px;
    margin-right:5px;
    float:left;
    background: rgba(0, 0, 0, 0.2);
    -webkit-transition: background 1s;
    -o-transition: background 1s;
    -moz-transition: background 1s;
    border-radius:2px;
    margin-top:31px;

}

.box:hover {
    background: rgba(0, 0, 0, 0.4);
    -webkit-transition: background 1s;
    -o-transition: background 1s;
    -moz-transition: background 1s;
}
.name {
    height:23px;
    width:auto;
    text-align:center;
    font-family:myfont;
    font-size:14px;
    color:#FFF;
    text-decoration:none;
}

.box img {

    float:none;
    margin-left:38px;
    margin-top:3px;
}

Answer №1

The containers are housed within div.navigation, which is set with a left margin of 256px. Even when the size of div.header changes, the left margin remains constant. If you desire to center the navigation within the header, you can utilize

.navigation {
    margin-left: auto;
    margin-right: auto;
}

This method ensures that it does not exceed the header's boundaries and adjusts the left margin based on the total width.

In response to your query, for the header to stay consistent, it needs a fixed width, such as

.header {
    width: 1200px;
}

Therefore, there is no need for min-width or max-width.

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

The Bootstrap carousel controls now add the carousel ID to the address bar instead of just moving to the next slide

I can't figure out why my carousel isn't working. The id of the carousel is showing up in the webpage's address, which usually happens when the 'bootstrap.js' file is missing, but I have included it. Can anyone help me troubleshoo ...

I am looking to arrange two div elements and one navigation bar into the header, positioning them at the top-left, top-center, and top-right using CSS. How

I'm attempting to arrange three divs within the <header>: div1 (logo) at the top left of the page, nav2 (menu bar) at the top center of the page, and div3 (social networks) at the top right of the page. However, I am unsure of how to achieve thi ...

What is the best way to ensure a div element on a printed page has a space between its bottom edge and the physical paper, as well as a space between its top

Within my div element lies a collection of other div elements. These elements contain lengthy text that may span multiple pages. I am attempting to print this text starting 50mm from the top edge of every physical paper, and stopping 20mm before the edge o ...

Implementing class changes based on scroll events in JavaScript

const scrollList = document.getElementsByClassName('scrollList'); function scrollLeft() { scrollList.scrollLeft -= 50 } function scrollRight() { scrollList.scrollLeft += 50 } #scrollList { display: flex; overflow: auto; width: 10 ...

Looking for assistance on how to automatically close the sidebar or pull navigation menu after clicking on a menu item

My website is designed to be responsive and includes a navigation slider that is hidden off-screen by default. The slider features a vertical push/pull bar that remains visible for users to access the menu. The entire navigation slider is fixed on the page ...

Emulating form functionality: How to programmatically open a link using PHP

Do you want to provide package tracking on your website like DHL does? With DHL, users can track their packages by visiting a specific URL, such as . When a tracking number is entered, it opens a new window with the following format: SOMENUMBER1234 If you ...

What is the best method to pass a JavaScript file array to a Node.js server?

Is it possible to transfer data from a Javascript file linked to an HTML page to a Node.js file on a post route without displaying it on the HTML page? If so, what is the best way to accomplish this? ...

Tracing the variable passed by Jquery (AJAX) within the PHP code on the server to identify and

My web-hosted server has a PHP file in a specific folder. I want to send data from an HTML form using Jquery AJAX and view those variables in the PHP code on the server side. Here is my Jquery AJAX code: function sendtoServer() { $.ajax({ ur ...

Identify the fields in the form that have been edited for easier reference

Seeking guidance on creating a form with interactive input box fields. When a user inputs something, the field highlights in orange. Moving to another field removes the highlight and focuses the new box. Clicking "save" stores the form data. Pressing "mo ...

Steps for Customizing the Font Style of a Certain List Item Tag <li>

I'm struggling to find the right CSS selector to specifically change the font of just one list item. Here's the current structure: <ul id="menu-applemain class="x-nav> <li>One</li> <li>Two</li> <li>Three</l ...

Learn how to showcase real-time stock information from Yahoo Finance on an Android device. See the JSON format provided below for guidance

finance_charts_json_callback( { "meta" : { "uri" :"/instrument/1.0/PTC/chartdata;type=quote;range=1d/json/", "ticker" : "ptc", "Company-Name" : "PTC Inc.", "Exchange-Name" : "NMS", "unit" : "MIN", "timezone" : "EDT", "curr ...

The correct way to reference images in the resources folder using a URL in CSS

After I generated a Maven dynamic web project using an archetype, I decided to organize the javascript, css, and image folders under the webapp folder. The structure now looks like this: myproject | main | | | java | | | resources | | ...

Reposition the button alongside the textarea

Seems like this is a common inquiry. I am still learning the ropes when it comes to CSS and JavaScript. I have a textarea with a button beneath it, and I would like the button to stay aligned with the textarea as I resize it! Any suggestions on how I cou ...

Allow the content to be scrolled

When it comes to my CSS script, I encounter no issues on larger computer screens. However, users with smaller resolutions like 1024 x 768 are experiencing problems viewing the entire HTML page. Only half of the page is displayed, making it impossible for t ...

transitioning backwards upon the removal and addition of classes in vue

Currently, I am working on creating a help button that triggers a help-dialogue box with some animations when clicked. This is the template I am using: <template> <div class="help"> <button v-if="theme" class=" ...

Annoying animation triggered upon loading of the page using AngularJS

I'm encountering an issue with a webpage element that has a hide/show animation. Despite the initial state being hidden, when the page loads, it still displays the hide animation. I attempted to set ng-show="false", but the hide animation persists upo ...

Exploring Ember Octane (version 3.22 and above): benefits of using {{on 'click' this.function}} over traditional onclick={{this.function}} method

When working with Ember Octane, there are two different ways to attach a function to an event in an hbs file. The first way is the EmberJS approach: {{on 'click' this.function}} Alternatively, you can use the classic HTML method: onclick={{this ...

Steps for styling an AngularJS Popup:1. Determine the desired appearance for

I have some code that displays a popup when clicked, along with its automatically generated CSS. I want to be able to make changes to the CSS by adding IDs or classes to it. How can I assign IDs or classes to this element so that I can easily target them f ...

What occurs when an image is unable to be rendered on the screen?

When an image cannot be displayed, what is the expected behavior of browsers? The information provided by official sources regarding this matter is intentionally vague. They mention that alt text should be utilized, but fail to clarify how it should be us ...

Aggregated Mvc Razor components

After creating a layout in ASP.NET MVC, I utilized a script bundle to load the jQuery library. Unfortunately, it seems that the jQuery library is not being loaded properly. The structure of my layout is as follows: <!DOCTYPE html> <html> < ...