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

Adding a dynamic click event in HTML using IONIC 4

I've created a function using Regex to detect URL links and replace them with a span tag. The replacement process is working fine, but I'm facing an issue where when I include (click)="myFunction()" in the span, it doesn't recognize the cli ...

Deactivate a dropdown option in Angular's uib-dropdown

Currently in my angular template, I am working on a dropdown menu using angular-ui. The requirement is to disable certain list items based on a property of the "company" object defined in the ng-repeat. I've already experimented with the disabled tag ...

Guidelines for Naming Data Attribute Values in JavaScript

When it comes to the Data Attribute Value, should one use hyphens or camelCase as a convention? Hyphen Example: <input type="text" name="some_input" data-target="to-grab-input-via-javascript"> Camel Case Example <input type="text" name="some_ ...

Does the <cite> tag go inside a link in HTML?

Whenever I include a citation in HTML using the <cite> tag, I typically place the link around the citation itself. For example: <a href="http://example.com/"><cite>Example Citation></cite></a> This method makes sense to m ...

Is there a way to transform this JavaScript function into a jQuery plugin?

Hey there! I've been using this JavaScript function to print a div, but now I realize that I need to switch to jQuery. Can someone lend a hand in helping me convert this to jQuery code? $(document).ready(function(){ function printData() { ...

What is the easiest and most straightforward method for deploying HTML and JavaScript in Service Mix?

I am currently working on a small HTML/web page project and I am interested in deploying service mix. Although I have knowledge of the web page side and I am familiar with service mix, I haven't ventured into using a simple HTML/JavaScript setup withi ...

Is your animation glitching due to axis restrictions?

I decided to create my own version of the Google Maps icon using Photoshop, and now I want to replace the current image with my duplicate when the link that wraps around both is hovered over. To achieve this, I used the position: absolute property to layer ...

What is the sequence in which the browser handles CSS?

I have a specific class that is being styled in multiple places on my website. I am curious about the order in which the browser reads and applies these different styles. Can you explain this process to me? Inline Style <div class="yellowtag" sty ...

Is there a way for me to extend an absolute div to the full width of its grandparent when it is within an absolute parent div?

Here is a structured example of my HTML and CSS: <div class="grandparent"> <div class="row">...</div> <div class="absolute-parent"> <div class="absolute-child">...</div> ...

Steps for inserting an item into a div container

I've been attempting to create a website that randomly selects elements from input fields. Since I don't have a set number of inputs, I wanted to include a button that could generate inputs automatically. However, I am encountering an issue where ...

Opening an HTML file in Eclipse is a simple process that can be

Q1) Is there a way to open this file in a browser for testing? Q2) Can I quickly open this in Chrome from Eclipse and test it? click here for image ...

Move the option from one box to another in jQuery and retain its value

Hey guys, I need some assistance with a jQuery function. The first set of boxes works perfectly with the left and right buttons, but the second set is not functioning properly and doesn't display its price value. I want to fix it so that when I click ...

Generating HTML widgets dynamically with jQuery: A step-by-step guide

Looking for a way to display an interactive widget on your page while allowing users to generate multiple instances and interact with them simultaneously? Imagine having a widget like this: <div id="my_widget"> <script type="text/javascript" ...

What is the best method for incorporating a YouTube embedded video into an image carousel using HTML and CSS?

I'm encountering an issue with my product carousel that includes an image and a video. The image displays correctly, but when I attempt to click on the video to have it appear in the main carousel view, it doesn't function as expected. Here is a ...

Tips for making a fluid DIV expand to fit the entire width of the page

My layout features fixed-width sidebars on the left and right, with a fluid main content area that fills the space in between using float:left. Here's an example: #left-sidebar {width: 200px;} #right-sidebar {width: 300px;} #main-content {margin-left ...

The gradient applied to the svg <text> element is failing to function

I'm currently working with an SVG element and trying to incorporate a <text> element with a gradient. Interestingly, the same LinearGradient successfully applies to one SVG but not to another. My question is whether a gradient can be applied to ...

The sticky HTML table header feature is functional, however, the header's border disappears while scrolling

Utilizing the react-bootstrap-table2 library in my React project, I added custom CSS to create a sticky top row effect: .table-container { overflow-y: auto; max-height: 500px; } .react-bootstrap-table th { position: sticky; top: -1px; background- ...

Troubleshooting a jQuery Selector Issue with a Dynamic Form

I developed a jQuery function to search for all the necessary inputs in a specific section of a website. function check_property_vars() { jQuery(this).parents('.property_group').find('div[id^="property_group_"]:input[required]:visible&a ...

Creating a fresh CSS class and utilizing its properties in JavaScript is the task at hand

Whenever I define a css class and attempt to access its member from JavaScript, the result always ends up being undefined. Where could my mistake possibly lie? function myFunction() { var x = document.getElementById("myId").style.myMember; document. ...

Guide on creating my inaugural HTML embeddable widget?

A client recently requested me to create a JavaScript (MooTools)/HTML/CSS/PHP based game as a deployable widget. This will be my first time developing a widget, so I am seeking advice and insights to help me navigate any potential challenges from experie ...