When you zoom in or out, HTML5 elements styled with CSS will dynamically adjust

Hey everyone, I have a question about a problem I'm facing with my HTML and CSS page.

The issue is that when I zoom in, the "Section" part moves underneath the nav bar, and when I zoom out, the footer moves next to the section part...

Below is a snippet of my HTML page:

<!DOCTYPE html>

<html>

<head>
    <meta charset="UTF-8">
    <title>MyWebsite</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">

</head>

<header>
   Header
  </header>


<body>



  <nav>
      <ul>
          <li>
             Tab1 
          </li>
          <li>
            Tab2 
          </li>
          <li>
             Tab3 
          </li>
          <li>
             Tab4 
          </li>
          <li>
             Tab5
          </li>


      </ul>
  </nav>



  <section id="">
 Section
  </section>

  <footer>
  Footer
  </footer>



</body>


</html>`

Here is the corresponding CSS code:

header
{
    width: 1325px;
    height: 150px;
    background-color: green;
    position: relative;
}

nav
{
    position: relative;
    width: 400px;
    height:  500px;
    background-color: teal;
    float: left;
    overflow: hidden;
}

section
{
    position: relative;
    float: left;
    width: 925px;
    height: 500px;
    background-color: blue;
}

footer
{
      float: left;
    width: 1325px;
    height: 50px;
    background-color: lime;
    position: relative;
    overflow: hidden;    
}

I appreciate any help and advice you can provide. Thank you!

Answer №1

Ensure that your body tag appears before the header in your HTML structure. Additionally, consider adding a wrapper element with defined width in your CSS.

To see an example, check out this fiddle: http://jsfiddle.net/msJLW/

<div id="wrap">
<header>
   Header
  </header>
  <nav>
      <ul>
          <li>
             Tab1 
          </li>
          <li>
            Tab2 
          </li>
          <li>
             Tab3 
          </li>
          <li>
             Tab4 
          </li>
          <li>
             Tab5
          </li>
      </ul>
  </nav>
  <section id="">
 Section
  </section>

  <footer>
  Footer
  </footer>

</div>

#wrap{
    width:1325px;
}
header
{
    width: 1325px;
    height: 150px;
    background-color: green;

}

nav
{
    width: 400px;
    height:  500px;
    background-color: teal;
    float: left;
    overflow: hidden;
}

section
{
    float: left;
    width: 925px;
    height: 500px;
    background-color: blue;
}

footer
{
      float: left;
    width: 1325px;
    height: 50px;
    background-color: lime;
    overflow: hidden;    
}

Answer №2

Tom's suggestion is spot on, and you may consider incorporating a container for your elements. Check out this demo: JSFiddle. Essentially, all of them are

position: relative

missing an absolutely positioned container to reference. By including a wrapper with the following CSS:

position: absolute;
height: 500px;
width: 1020px;

Everything stayed in alignment. Let me know if this wasn't what you had in mind!

Answer №3

Although the reason for its movement is unclear to me, I have a simple solution: enclose it all in a wrapper. Here's a snippet you can copy and paste:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8>
    <title>MyWebsite</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
  <div class="wrapper">
    <header>
      Header
    </header>
     <nav>
      <ul>
        <li>Tab 1</li>
        <li>Tab 2</li>
        <li>Tab 3</li>
        <li>Tab 4</li>
        <li>Tab 5</li>
      </ul>
    </nav>
    <section id="">
      Section
    </section>
    <footer>
      Footer
    </footer>
  </div>
</body>
</html>

If there are any elements not contained within the <head> tags, make sure they are inside the <body> tags, excluding the doctype and <html> tags - this includes your <header> tags.

The above code wraps everything in a "div", which helps segment a webpage. They are easily stylized using CSS, so don't forget to add the following code at the end of your CSS file:

.wrapper {
    width: 1325px;
}

Feel free to reach out if you need more assistance :D

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

Using jQuery to manipulate the image within a specific div element

I'm facing an issue with locating the img src within a div. I've written a function to find all the divs with specific ids: function identifyDiv(){ divArray = $("div[id^='your']"); divArray = _.shuffle(divArray); } This is the ...

Is there a way to create a blurred background effect while the popup is in use?

I prefer my popup to have a dark or blurred background when active. The popup itself should remain the same, with only the background being darkened. I would like a dark layer overlaying the entire page. This script should be compatible with any website wh ...

Instructions on removing an HTML element from a div that has the attribute contentEditable

Here is an example of HTML code: <div id="editable" contentEditable="true"> <span contentEditable="false">Text to remove</span> </div> I want to be able to delete the entire span element (along with its text) with just one bac ...

Click on link after animation has finished

I'm currently facing an issue with my script not functioning correctly. The code I'm utilizing is from a resource provided by Codyhouse to implement a 3D rotating navigation menu on my webpage. Essentially, when you click the hamburger icon, it o ...

The responsive class seems to be malfunctioning within the Laravel 5.3 framework

I have a project that involves Laravel and Vue.js. In my Laravel project, I am importing Bootstrap CSS using the following line: // Bootstrap @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; This import is done in the app.scss file. ...

Tips for styling custom buttons within the active editor popup of tinyMCE using CSS

Looking to enhance my tinyMCE active editor popup with custom CSS. Check out the screenshot provided for reference https://i.sstatic.net/vdVDF.png. Below you can find the code snippet used as a reference: tinymce.activeEditor.windowManager.open({ tit ...

Vuetify - Best practices for vertically aligning rows in a v-treeview component

Just getting started with Vue js, so pardon me if this is a silly question. I've scoured the internet and can't seem to find a solution. I'm working on a v-treeview displaying a folder structure, with descriptions of each folder in a separa ...

What steps can I take to ensure that the full tingle modal, which includes an image, is visible when the

Upon loading the page, I noticed that if the browser width is greater than 540px, the modal displaying an image gets cut off (see figure below). What steps should I take to ensure that the vertical scroll bar appears immediately? https://i.sstatic.net/cJv ...

Execute a Python script even if Python is not installed on your device

One of my clients needs to access certain files through sftp. I was able to accomplish this using Python on my computer. However, I now face the challenge of implementing the same solution on his laptop without requiring him to install Python. What would ...

Applying a specified style to a pseudo element using the ::after selector to display an

Can anyone help me with adding a pseudo element ::after containing an icon (from FontAwesome) to my Bootstrap Vue ProgressBar? I want this icon to be dynamic and move along the progress bar line when I click. Here is my current implementation, where the Pr ...

Is there a way to create an input field that accepts only numbers and behaves like a password field simultaneously?

I am attempting to develop an input field for entering a PIN. I would like the PIN to be masked on mobile devices, similar to how passwords are obscured in password input fields. I came across a suggestion on stackoverflow regarding this, but unfortunately ...

trigger a label click when a button is clicked

I am in need of assistance with simulating a label click when a button is clicked. I attempted to make the label the same size as the button so that when the button is clicked, it would check my checkbox. I then tried using JavaScript to simulate the label ...

Is it possible for me to route a URL to a particular content generated by Ajax on a separate webpage?

I appreciate anyone taking the time to help with this, especially since I already had to get 12 stitches. Here's what I'm dealing with: mysite.com/documentation - page with a menu and content section (content will load dynamically via Ajax w ...

Having trouble with jQuery Animate when trying to change the background-color property?

So, I was experimenting with the jQuery .animate() function and decided to change the background color of a div based on how many pixels the user scrolled. Surprisingly, it didn't work as expected. After switching to the .css() function instead, every ...

Utilizing vue-router to create two separate navigation bars where only one link is highlighted as active

In my setup, I have implemented two sections with navigation structured as follows: <ul class="navigation-list"> <li v-for="(route, index) in navRoutes"> <router-link :to="route.path"> <span>{{ route.name }}</span> ...

Troubleshooting issue with JQuery AJAX loading Bootstrap Dropdowns

I have a website on GitHub Pages that uses Bootstrap, but I'm having issues with the drop-down menu in the navbar. Sometimes it works and sometimes it doesn't. I am using $("#nav").load("url"); to load the navbar so that I can make changes and ha ...

What is the proper way to mention JavaScript packages when including them as parameters in Angular elements within HTML?

I was looking to enhance the command to be more authoritative. <div (click)="lastCall(999)">click me</div> My attempt to utilize Number.MAX_SAFE_INTEGER resulted in an error from my computer stating that it wasn't recognized. As a result ...

I'm looking to create a unit test for my AngularJS application

I am currently working on a weather application that utilizes the to retrieve weather data. The JavaScript code I have written for this app is shown below: angular.module('ourAppApp') .controller('MainCtrl', function($scope,apiFac) { ...

Is it possible for me to create a CSS class based on a condition using [ngCLASS]?

I am struggling with logic writing in my Angular2 project. On a HTML page, I have two buttons - YES and NO that I want to style with different colors. I have set up a condition in the div tag like this: ngClass="'result'?'yes':' ...

Troubleshooting Problems with CSS Three-Column Layout

Struggling with aligning domain names in a 3 column setup, I have been attempting this for some time now without success. I am new to this and could use some guidance. Here is the code: TPL file <div> <p class="center">{foreach key=num it ...