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.

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

What steps can be taken to launch a website in Chrome's headless mode while navigating around any blockers of the mode itself

Below is the XPATH I am using to extract price information from various websites, except for Myntra. This XPATH works perfectly on my local Windows system with Selenium, Python3 version, and Chrome driver. Driver path: driver = webdriver.Chrome("/usr ...

Explore relevant Pill information dynamically based on the image that was clicked in Angular

In this particular situation: Using Angular 1.7.2 Utilizing Bootstrap 3 Encountering some challenges after the user interacts with the image: Current Behavior: Upon clicking any image, a modal window appears displaying relevant content. If image 1 is ...

Expansive Carousel Feature with Ng Bootstrap

In my Angular 5 application, I am utilizing the Carousel component from "@ng-bootstrap/ng-bootstrap": "^1.1.2". I am trying to display pictures in full screen but when I press F11, the image appears like this. I am unsure of which CSS properties to apply ...

Using Jquery to toggle the visibility of divs based on radio button selections

I am struggling to hide the divs with the radio buttons until their title is clicked on. However, I am facing issues as they are not showing up when their title is clicked on. Any assistance would be greatly appreciated. SPIKE <!DOCTYPE html> &l ...

Is it possible to activate the nearby dropdown based on the user's selection?

On my html webpage, I have a form that consists of three dropdown menus each with different options: The first dropdown (A) includes choices from 1 to 6, as well as 'not set'. The second dropdown (B) allows selections from 1 to 7, and also has ...

How to retrieve an element in jQuery without using the onclick event listener

I'm looking to extract the element id or data attribute of an HTML input element without using the onclick event handler. Here is the code I currently have: <button class="button primary" type="button" onclick="add_poll_answers(30)">Submit</ ...

Utilizing the powerful combination of TailwindCSS and Next.js Image to achieve a full height display with

Trying to utilize the Next.js' <Image> component with the layout=fill setting, I created a relative div housing the Image tag. However, I am looking for a way to set the height based on the Image's height. Came across this example, but the ...

Tips for changing between two texts within a button when clicked

Seeking a solution for toggling between two different texts inside a button when making an ajax call, with only one text displayed at a time. I'm facing difficulty in targeting the spans within the button specifically. Using 'this' as conte ...

Tips for preventing redundant data entry in a table

Currently, my table displays like so: The structure of the HTML for the table is as follows (only a snippet is shown, as the rest looks similar): <table class="table table-bordered table-condensed"> <tr> <th>Days</th> ...

Optimizing Open Graph tags for sharing WhatsApp links

I am utilizing Open Graph tags to optimize sharing on social media platforms. The image I have specified is 1200 x 630 pixels and displays correctly on Facebook as well as Whatsapp: <meta property="og:image" content="https://emotionathlet ...

Different approach to handling overflow without using the hidden property in CSS

Having trouble with my CSS layout I've created a form within a fixed 500 pixel width div that is centered on the page using margin auto; To create a table-like structure within the div, I used div elements as rows. Due to varying heights of these ro ...

The linking process in AngularJS is encountering difficulties when trying to interact with

I've already looked at similar questions, and my code seems correct based on the answers provided. It's a very simple beginner code. <html ng-app=""> <head> <title>Assignment</title> <script src=" ...

Challenges encountered with input outcomes

I am facing an issue with input results. I have a button that triggers a function to check for empty input fields. However, when I click the button, it always falls into the last if statement and displays as if the fields are not empty. I have already att ...

CSS: The button appears to be slightly lower than the label

For more information, check out this GitHub link Here is the HTML code snippet: <div class="col-md-12"> <div class="col-md-2"> Processing </div> <div class="col-md-4"> <button class="btn btn-primary">Hello</ ...

To create a distinctive design, the HTML5 wrapper will specifically enclose the Header element

After using a border, I discovered that my wrapper is only wrapping the header and not extending down to the footer. Can anyone offer some guidance on how to wrap the entire content from the header to the footer? I've come across suggestions to speci ...

The sticky navigation bar becomes fixed at the top prematurely

Having a sticky navbar on my Bootstrap-based website, I've implemented the following jQuery code: $(document).ready(function () { var flag = false; function stickNav() { $(".navbar-default").affix({ o ...

There seems to be an issue with the visibility of the b-button within the b-table component in

I'm new to Vue Js and I'm having trouble with my b-button not displaying in my table. I can't figure out why. Below is my HTML code: <div id="listlocales"> <div class="overflow-auto"> ...

What is the process for altering the color of an HTML output depending on its values?

I created a simple HTML code to showcase some outcomes. The possible results are SUCCESS, Failure, and Still Failing. I want these results to be displayed with corresponding colors, such as green for SUCCESS, and red for both Failure and Still Failing. I ...

Unable to retrieve data from the database within PHP code

I have successfully built a shopping cart website utilizing SQL, HTML, and PHP. Below is the code snippet for the 'Add to Cart' button: <form method="post" action="cart.php" class="form-inline"> <input type="hidden" value="&apos ...

What specific quirk in Firefox is responsible for this behavior, and is there a way to replicate it in standards mode?

In Firefox, this particular document displays differently in standards mode compared to quirks mode. When in quirks mode, the div fills the entire screen, but in standards mode it does not. I went through the MDN quirks list and couldn't pinpoint a sp ...