Navigation bar experiencing resizing problem, refreshing resolves the issue

I've been struggling with this problem all day.
I'm attempting to create a header that consists of a logo on the left and a list on the right.
I want it to resize along with the navigation below the logo.
I WAS ABLE TO ACHIEVE THIS but when I resize it back to a larger width, my nav remains below the logo.

Being new to web development, any tips or advice would be greatly welcomed.

<!DOCTYPE html>
<html>
  <head>
    <title> Website</title>
    <!-- links -->
    <link rel="stylesheet" href="style copy.css" type="text/css" />
  </head>
  <body class="body">
    <!-- Main Menu -->
    <div id="mainMenu" class="mainMenu">
      <div class="logo"></div>
        <nav class="rightThenMid">
          <ul>
            <li class="active first"><a href="#home">HOME</a></li>
            <li><a href="#services">Services</a></li>
            <li><a href="#contact">Contact</a></li>
          </ul>
        </nav>
      </div>
    </body>
  </html>

CSS

body {
  clear: both;
}

.body {
  clear: both; 
  margin:0;
  padding:0; 
}

.mainMenu {
  width: 100%;
  height: 70px;
  background-color: #121212;
  z-index: 10; 
}

.mainMenu nav {
  height: 90px;
}

.mainMenu nav ul {
  height: 100%;
}

.mainMenu nav ul li {
  display: inline-block;
  height: 100%;
  font: 11px/6.36em "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: 0.25em;
  list-style-type: none;
  text-transform: uppercase;
}

.mainMenu nav ul li.first a {
  padding-left: 0px;
}

.mainMenu nav ul li.last a {
  padding-right: 0px;
}

.mainMenu nav a {
  display: block;
  padding-left: 18px;
  padding-right: 18px;
  text-decoration: none;
  color: #fff; 
}

.mainMenu nav ul li a:hover, .mainMenu nav ul li.active a {
  color: #6159c1;
}

.rightThenMid {
 float: right;   
}

.logo {
  display: inline-block;
  width: 300px;
  height: 70px;
  background-image: url('img/companyLogo.png');
  background-repeat: no-repeat;
  margin: auto;
}

ul, li, nav, p {
  margin:0;
  padding:0;
  border:0;
  outline: none;
  font-size:100%;
  vertical-align:baseline;
  background:transparent;
}

nav ul,ul,ol {
  list-style:none;
}

@media only screen and (min-width : 150px) and (max-width : 700px) {
  .body {
    clear: both; 
    margin: 0 auto; 

  }

  .mainMenu {
    height: 140px;
  }

  .mainMenu nav ul {
    height: 100%;
    display: inline-block;
    list-style-type: none;
  }

  .rightThenMid {
    display:block;
    margin:0 auto;
    text-align:center;
    float: none;
  }

  .logo {
    display:  block;
    margin:auto;
    width: 300px;
    height: 70px;
    background-image: url('img/companyLogo.png');
    background-repeat: no-repeat;
  }

}

Answer №1

To resolve the issue, consider adding float: left to your .logo without using a media query, and then include float: none for .logo within the media query.

It seems like the problem arises from applying a float property only to .rightThenMid, but not to .logo.

Check out the Working Fiddle here!

.logo {
  ...
  float: left;
}

@media only screen and (min-width : 150px) and (max-width : 700px) {
    .logo {
      ...
      float: none;
    }
}

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

Turn off Chrome Autofill feature when placeholders are being used in forms

I am encountering difficulties with Google autofill for fields that have placeholders. Despite attempting various solutions provided at: Disabling Chrome Autofill, none of them seem to work as needed. The challenge is to create a form with different field ...

Combobox fails to dynamically update

Currently, I am attempting to create a dropdown menu that dynamically updates based on changes made in another dropdown menu. Despite my efforts, I have not been able to find a suitable solution and feel quite lost at this point. In an attempt to troubles ...

Preventing HTML form submission after displaying an alert in Vanilla JavaScript

I have created a quiz using HTML with validation. The next step is to score the quiz in JavaScript. The scoring system works fine, but I want to prevent the form from posting to result.html if the user scores 0 on the quiz. I've managed to display an ...

"Is there a way to implement a sequence of fadeIn() followed by fadeOut() and then insertAfter

I have created a simple div fade cycle. Some of the divs are within an outer div, which is then placed in another outer div. I've written a script that cycles through these divs by fading them in and out. However, there seems to be a problem - the div ...

Adjusting picture dimensions with percentages in canvas and jquery

I'm currently working on a one-page project that involves a canvas where users can click to add or place images randomly. I have made progress with most of the functionality, but as a beginner in jquery and canvas, I am struggling to set a maximum siz ...

Vertical tab design in Bootstrap does not automatically switch tabs

I'm managing two separate tab boxes that switch content when clicked or over a 5-second period. The left box is functioning correctly, but the right box is changing the active state without updating the content. Here's the HTML for the left box ...

instructions on sending the complete product quantity to the payment gateway

I am currently in the process of developing an ecommerce website using Django. When a user clicks on checkout, an HTML billing form appears prompting them to enter their address and email information. Previously, I successfully passed data such as email t ...

How can I alter the background color while performing a transformation in JS/CSS?

I'm currently working on achieving a flipboard effect for some divs, where one side is white and the other is black. Here's what I have so far: setInterval(function () { document.getElementById('test').classList.toggle('flipped& ...

Enhance your browsing experience by inputting valuable information into the

I am looking to enhance a text box by adding values. The text box already has a default value of 10, and I want to create a button that will add new text boxes with a limit of 4. My goal is to continuously add values from text box 1 to text box 4. For exa ...

JQuery Mobile: Adding fresh, dynamic content - CSS fails to take effect

I've encountered this issue before, but I'm still struggling to resolve it. When adding dynamic content to a page (specifically a list-view), the CSS seems to disappear once the content is added. I've tried using the trigger("create") functi ...

Struggling to find solutions for debugging HTML codes in Visual Studio Code and linking my CSS page to my HTML page

I ran into some issues with linking my CSS stylesheet to my HTML pages. I tried using the <link rel="stylesheet" href="style.css"> command, where style.css is the name of the file. However, for some reason, it wasn't working ...

Using Semantic-UI causes issues with the functionality of the height property set to 100%

View my CodePen here <head> <meta charset="utf-8"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.min.css"> </head> <body> <div class="ui secondary pointing menu" id=" ...

How can I use HTML and jQuery to send a button click event to a .py file using AJAX and cgi in web development?

I have encountered a challenge with posting data from button clicks on an HTML page to Python CGI for insertion into a PostgreSQL database. My script seems to be struggling with this task. Here is the structure of my HTML, ajax, and javascript: '&ap ...

What is the reason for the failure of this code to store data in local storage (undefined)?

After creating a new div with data from an input form, I noticed that the first div properly saves the inputted data. However, when I try to input new data, the div displays an undefined value. first attempt second attempt 0: {name: "Milk", amount: "30"} ...

Using JavaScript and PHP to dynamically update a field based on two input values within a row of a table

Currently in the process of developing a dynamic profit margin calculator for a personal project. Overview Data is retrieved from a database table using SQL and PHP After necessary validations, the data is dynamically displayed as rows in an HTML table ...

How can we stop the constant fluctuation of the last number on a number input field with a maxLength restriction

In my ReactJS code, I have an input field that looks like this: <input type="number" onKeyPress={handleKeyPress} maxLength={3} min="0" max="999" step=".1" onPaste={handlePaste} /> Below are the functions associated w ...

Ways to troubleshoot an unusual margin issue in a static column of an HTML table

I have been exploring various resources to create an HTML table with a fixed first column using CSS only. Despite my efforts, the fixed column is consistently appearing lower than the rest of the content, and I'm unsure why. Check out the code I&apos ...

When the label is clicked, the radio button does not have a selected value

I am experiencing some strange behavior with a radio button, as shown in the attached GIF. Whenever I click on the label, the selected value disappears and the radio buttons become unchecked. I have been unable to identify the cause of this issue. I am ...

Modify animation trigger when mouse hovers over

I am looking to create a feature where a slide overlay appears from the bottom of a thumbnail when the user hovers over it, and retracts when the user is not hovering. animations: [ trigger('overlaySlide', [ state(&ap ...

Tips on Including Static Header and Footer in Multiple HTML Pages

What is the best way to reuse a header and footer on multiple HTML pages without repeating code? I have 5 HTML pages that all need to include the same header and footer elements. How can I efficiently reuse these components across all pages? ...