Prevent elements on the page from shifting when the browser is resized using HTML

Is there a way to prevent elements from moving when the browser is resized? When I make the browser window smaller, everything shifts position towards the left, causing text to overlap with the menu bar. Is it possible to keep everything in place even when resizing the window?

Here's the beginning of my HTML code:

<head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" type="text/css" href="css/alternativeCSS2.css" 
title="bigsheet"/>
  <link rel="alternate stylesheet" type="text/css" 
href="css/alternativeCSS2.css" title="mediumsheet"/>
  <link rel="alternate stylesheet" type="text/css" 
href="css/alternativeCSS3.css" title="smallsheet"/>
  <link rel="alternate stylesheet" type="text/css" 
href="css/alternativeCSS4.css" title="specialsheet"/>
  <script type="text/javascript" src="script/CTEC1800-Stylesheets(4).js" >
</script>
  <title>Historical Pioneers</title>
</head>
<body onload="chooseStyleBySize()">
  <div id="layout">
     <div id="swapping">
        <p>
           <select onchange="setActiveStyle(this.value)">
              <option value="bigsheet">For big pages</option>
              <option value="mediumsheet">For medium-sized pages</option>
              <option value="smallsheet">For small pages</option>
              <option value="specialsheet">For special pages</option>
           </select>
        </p>
     </div>
     <div id="header">
        <h1 id="logo"><img src="img/logo.png" width="200px" height="70px" 
alt="logo" /></h1>
     </div>
  </div>
  <div id="nav" class="box">
     <ul class="nav">
        <li id="active"><a href="home.html">Home</a></li>
        <li><a href="Hitlers Biography.html">Adolf Hitler's Biography</a>
</li>
        <li><a href="Winston Churchill.html">Winston Churchill's 
Biography</a></li>
        <li><a href="About Us.html">About Us</a></li>
        <li><a href="Contact Us.html">Contact</a></li>
     </ul>
  </div>
  <div id="container" class="box">
     <div id="intro">
        <div id="intro-in">
           <h1>60 million men fought in 'The War to End All Wars', It ended 
nothing..</h1>
           <p class="intro">
              "Putting history in it's place". For many years we have been 
collecting, researching and interpreting historical information from the 
World War 2, How the key figures including Adolf Hitler and Franklin D. 
Roosevelt influenced this great war between 1939 to 1945. 
              Some information that was not yet looked into properly that 
was very well important and how it all began in the first place.
           </p>
        </div>
        <div  id="hr">
           <hr />

This is my CSS Code:

/*--------------------- Main Body --------------------- */

* {
margin: 0;
padding: 0;
 }
body, div, span, p, a, img, ul, ol, li, table, th, tr, td, form, fieldset, 
legend, dl, dt, dd, blockquote, applet, object {
border: 0;
}
p {
margin: 15px 0;
}
body {
padding: 0;
background-color: #ededed;
background: #fff url("../img/bg1.jpg") repeat-y;
font: 0.8em/1.5 "arial", sans-serif;
color: #354146;
text-align: center;
width: 100%; 
}

#layout {
}

#header{
text-align: left;
margin-left: 30px;
}

#swapping{
text-align: left;
margin-left: 45px;
}

#container{
margin-left: 40%;
clear: both;
width: 100%; 

}

/*--------------------- Horizontal Navigation Menu --------------------- */

#nav {
margin: 0;
height: 100%;
margin-top: 20px;
}
#nav ul {
list-style-type: none;
width: 14%;
min-width:265px;
height: 100%;

clear: both; 

text overflowing to the menu bar

Answer №1

If you want to ensure a responsive website, it's best to avoid fixing the width of your HTML body. Responsive web design is key in ensuring your site adapts to various screen sizes and resolutions.

To achieve this, consider using media queries in your CSS instead of setting a fixed width:

@media (max-width: [pixel_size]px) {
    /* Styles for smaller screens */
}

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

Head styles for tinyMCE

When viewing the tinyMCE example on the official website using Firefox, you may notice the editor blinking. This issue seems to only occur in Firefox, possibly due to external CSS files for the editor. I am considering adding all CSS rules directly into th ...

Place the outcome of the function into the div element's attribute

As a newcomer to HTML and JavaScript, I recently dove into using 3Dmol.js. Following a tutorial, I was able to create this code snippet that actually works: <script src="http://3Dmol.csb.pitt.edu/build/3Dmol-min.js"></script> <div id="el ...

The performance of my Wordpress site is being hindered by the slowdown caused by Admin

I have a Wordpress website focused on winter sports vacations in Iceland: link Every plugin, WordPress core, and theme are up to date. Using Woocommerce for my online store. However, activating the Woocommerce plugin causes the site to slow down signific ...

What could be causing my transform scale to not function properly in Bootstrap?

As a complete beginner, I am currently in the process of learning bootstrap. I have noticed that the animation breaks when I apply it, specifically the scaling part. Interestingly, the animation works perfectly fine without Bootstrap. I am wondering if the ...

Exploring the functionality of textareas within iframes on iPad

There is a known issue where textareas and inputs do not function properly on iPad Safari when placed inside an iframe. For more information, visit: This bug can easily be reproduced on iOS 7, but seems to work fine on iOS 8. Despite this issue, I am in ...

Unable to click on an input field with the mouse after selecting a background image

When working on an HTML page, we encounter a form with user id and password fields along with a background image. Initially, everything seems fine as we can select the input fields and enter data without any issues. However, if we happen to click on the ba ...

Upon the image being clicked, the form will be automatically submitted

Check out my code snippet: <form action="telecallerinfo.php?action=modify&id=<?php echo $id;?>" method="post" enctype="multipart/form-data"> <table class="panel1"> <tr> <td>Caller Name:&nbsp;<input name ...

Tips for customizing the appearance of a Horizontal Splitter panel in GWT version 1.5

I need to customize the style of the right side of a horizontal splitter panel. While GWT 1.7 offers support for individual panel styles, our project is currently on GWT 1.5. Here is the GWT code snippet: HTML div1 = new HTML("Div 1"); div1.setWidth("200 ...

What is the best way to ensure that an element remains fixed at the bottom of a div or card

I am currently working on creating cards that contain a link at the end. My goal is to have these links consistently displayed at the bottom of the div, regardless of the text length. Currently, they appear at the end of the text content. Is there an easy ...

Why do images not show up when they are in the same directory in HTML?

article.uk{ background-image: url("GB_Flag.jpg"); background-color: #95a5a6; background-repeat: no-repeat; background-position: right top; width: 75%; background-size: contain; color:#d98880; } <a href="GB.html" target="Great_Britain_Page"> < ...

Using a Do/While loop in combination with the setTimeout function to create an infinite loop

Having trouble with this script. The opacity transition works fine, but there seems to be an issue with the loop causing it to run indefinitely. My goal is to change the z-index once the opacity reaches 0. HTML <div class="ribbon_services_body" id="ri ...

To add an image, simply click on the designated area instead of using the traditional file input button. The image will then be displayed in the specified image container and resized on the client-side

Objective: I am aiming to enhance the image upload functionality by enabling users to click on an <img> element to initiate the file selection process, instead of using the traditional <input type="file"> button. There will be three placeholde ...

The styles defined in CSS do not have an impact on EJS templates that have GET route paths stacked

I have a CSS file located in the public directory and two EJS templates in the views directory. The CSS file works fine when using this route: app.get('/theresa', (req, res) => { res.render('templates/home') }) However, when I ...

Targeting multiple frames in HTML

Have you ever tried clicking on a link and opening three different pages that target three different frames simultaneously? I've managed to open two separate pages targeting two distinct frames using href combined with the onclick function and locatio ...

Is it possible to only make the text in a Bootstrap button act like a link, instead of the whole button itself?

As I start learning HTML and CSS with the help of Bootstrap, I'm encountering an issue with button functionality. The text within the button is acting like a link, but the entire button should be clickable. I'm not sure if I need more than just t ...

The selection form does not display a preview of the options

I recently discovered that the CSS I added is causing the preview of select options in my form to disappear. Despite searching online, I have been unable to find a solution to this issue. Here is the problematic CSS code: .form-control{ height: 50px; ...

What is the best way to categorize items in Angular lists based on their type

Lately, I've been delving into Angular and I'm facing a challenge - I want to split a list into two based on their type and display them in separate fields. My main query is: can I achieve this by using a for loop in the .ts file, or is there a s ...

What could be causing justify-content: flex-start; to not function as expected?

Can someone help me with my flexbox navbar? I set the justify-content property to flex-start, but the content inside the container is not aligning correctly. You can see the output and code here: output html, body { backgr ...

What is the best way to calculate the time elapsed between two consecutive double clicks using jQuery?

I am trying to calculate the time difference between two clicks on a single button. Here is my code snippet: <a href="#">click here</a> My current JavaScript code to capture the time of each click is as follows: var clickedTime = '&apos ...

Incorporating an additional row into a material table

Currently, I have implemented a mat-table with various features including drag and drop functionality and dynamic columns. However, I am facing an issue while trying to add row filters under the table header. I attempted to simply insert a <mat-row> ...