Objects shifting position as the browser window is resized or zoomed

I've scoured through numerous examples, but none seem to work for my specific situation. On my webpage, I have multiple tables nested within a <div>, which serves as a background element (as it doesn't cover the entire screen). However, whenever the window is resized or zoomed in/out, everything overlaps and creates quite a chaotic mess.

My objective is to achieve a layout similar to Stack Overflow, where regardless of resizing or zooming, everything remains in place without any movement. Here's how my background and tables are defined:

#bluebackground {
    background-color: #a4ceff;
    height: 50%;
    width: 90%;
    position: absolute;
    top: 20%;
    left: 5%;
}

.table1 {
    color: white;
    margin-bottom: 10px;
    font-family: 'Lato', Calibri, Arial, sans-serif;
    font-weight: bold;
    border-collapse: collapse;
    border: 3px solid white;
    border-radius: 3px;
    width: 90%;
    top: 50%;
    left: 5%;
    padding-bottom: 0px;
    position: relative;
    padding-left: 0px;
    padding-top: 0px;
    padding-right: 100px;
    font-size: 80%;
}

Answer №1

Avoid using percentages to specify the width and height of your elements, as this causes them to resize based on the parent element. If the parent element is the window, resizing the window will also change the size of the elements inside it. It's better to assign fixed sizes to your elements.

#bluebackground {
background-color: #a4ceff;
height: 500px; 
width: 500px;
position: absolute;
top: 200px;
left: 20px;
}

.table1 { 
width: 200px;
top: 100px;
left: 20px;
font-size: 14px; 
}

Check out: http://jsfiddle.net/Y6bcZ/, where you can see that resizing the display window does not affect the div size.

You'll need to determine the pixel values for each element yourself. I kept the table in percentage since the parent div (bluebackground) now has a fixed size, preventing the table from changing size.

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

Extracting the URL of the @font-face declaration in CSS with the use of JavaScript

Currently, my CSS file contains numerous @font-face tags. Each tag specifies a unique font-family and src URL. @font-face{ font-family: Garamond; src: url('ePrintFonts/pcl_91545.ttf'); } @font-face{ font-family: C ...

Please indicate the value of the JQuery class

How can I display the value of the selected button? All buttons have the class "nummer" and their values should appear on the display. Is there a better approach to achieve this? JQUERY $(document).ready(function() { $(".nummer").click(function() { ...

Adjust the width of the initial column in the table and ensure it remains noticeable

I am a beginner with bootstrap and I find it extremely useful. I have encountered a problem with a table I am working on. I am trying to set the width of the first column and keep it always visible, but I am having trouble achieving this. I have successful ...

What is the best way to set a background image to 100vh on mobile devices and 50vh on desktop screens?

Currently learning about bootstrap, I am in the process of creating a hero section for my website. My goal is to have the background image in the hero section take up 50% of the webpage on large screens, but switch to 100% on smaller screens. I suspect th ...

Node.js post request body is still showing as undefined despite using body-parser

Hello everyone, I am currently using Node.js to implement a Dialogflow chatbot. My goal is to extract parameters from an HTTP POST request. To achieve this, I utilized Postman and made sure to set the content type to JSON in the header. Below is the code f ...

Issue with submitting Laravel form using post method

I've encountered an issue with a form that is supposed to post a title and a body, but when I submit it, nothing happens. I have included a csrf field and I am using the post method. Despite trying various methods to declare the action and the method ...

Sequence of background colors not altering as intended

After clicking a button, I included the following jQuery code in a code snippet on my WordPress site: jQuery("#cf_course_planner tr").css("background-color", "#f66"); jQuery("#cf_course_planner tr:eq(0)").css(& ...

Creating a Drop-down Menu Item using React Material UI

I am experiencing an issue with displaying a MenuItem in my Dialog2 within my React app. Despite setting the zIndex: 1900 to a higher value than the two dialogs, the MenuItem remains hidden behind the dialogs instead of appearing at the front. Please revi ...

The PHP code encountered a syntax error due to an unexpected $EOF on the final empty line

I've been tasked with maintaining an old website that went offline due to script errors. I managed to resolve most of the issues in the script, but there's one error that's giving me trouble. The site is showing a syntax error that says "une ...

The Jquery Load() function is causing [object object] to be returned instead of the element ID value when retrieving it

I am pulling a value from a MySQL query result in page.php and displaying it in display.html. I am successfully showing the value "VALUE368" in the div ID on display.html. However, I also want to log "VALUE386" in the Firebase Realtime Database. I am attem ...

The jQuery animate function is being executed just a single time using setTimeout

Recently, I created a function that updates text inside a DIV and animates it after a delay of a few seconds. The animation is working smoothly, but I'm facing a challenge in making it repeat endlessly. I attempted to use setTimeout to achieve this, b ...

Effortless code formatting with VS Code for TypeScript and JavaScript

Does anyone know of any extensions or JSON settings that can help me format my code like this: if(true) { } else { } Instead of like this: if(true){ } else { } ...

The transformation of all relative URLs into absolute URLs is carried out

The issue at hand seems to be peculiar to Chrome and Firefox, as IE does not exhibit the same behavior. In my angular application, I've noticed a strange phenomenon. Once a specific view is loaded, all XHR requests made using relative paths are autom ...

Is it considered acceptable to include a stylesheet inside the <body> element?

When dividing my web pages into sections, such as headers and content, I find it challenging to avoid placing links to external stylesheets within the <body> tags. I prefer not to combine all styles into one large file or include all stylesheets in ...

Guide to embedding a component within another component using route based rendering

My routing configuration looks like this: <Provider store={store}> <BrowserRouter> <Route path="/" component={App} /> <Route path="/customers" component={Customers} /> <Route path="/tickets" componen ...

I am facing difficulties when trying to map the data using react js/axios

After removing the map function from the code, I encountered an error stating that map is not a function. Can someone please assist me with this issue? Here is the updated code: const [text, setText] = useState([]); const axios = require('axios&ap ...

The Gatsby and React navigator

Hey there, I've run into a little snag while working on my React component. I'm trying to display a pop-up using JS, but when I try to build my Gatsby site, I encounter an error stating: WebpackError: ReferenceError: navigator is not defined. Bel ...

Why is it that my jquery code seems to be struggling with calculating the count accurately?

I'm currently working on restricting keyword input on my website. My goal is to automatically add a 'span' tag to any keyword entered by a user, as shown in the example html code below. Although I can limit the number of words, the count i ...

I encountered an issue with Array map when attempting to access the data during a dynamic rendering process

function UserTransactionsComponent1() { const [accounts, setAccounts] = useState(); useEffect(() => { async function fetchData() { const res = await fetch( 'https://proton.api.atomicassets.io/atomicassets/v1/accounts' ...

How can I keep the size of a Bootstrap button consistent while wrapping text inside it?

Is there a way to wrap or resize text inside a Bootstrap button without changing the button size? I have multiple buttons that need to be aligned properly. I tried using this class, and while the text wraps, the button grows in size, causing alignment iss ...