What is the best way to adjust the size of an HTML element without impacting its surrounding elements?

I'm currently working on an HTML page that features a draggable and zoomable grid.

</head>

<body>
<div id="header">
    <h1>Header</h1>
</div>
<div id="main">   

    <div id="top_div">          
    <!-- some GUI -->
    </div>
    <div id="central_container">
        <div id="grid_container_static">
            <div id="grid_container_movable">
                <table id="grid">
                </table>
            </div>
        </div>
    </div>

    <div id="bottom_div">
    <!-- some GUI -->
    </div>
</div>

<script>
$( function() {
        $("#grid_container_movable").draggable();
    });
</script>

Relevant CSS:

<style>
body, html{
    margin: 0px;
    display: flex;
    flex-direction: column;
}

* {
   box-sizing:border-box;
}

body{
    height: 100%;
}

#header{
    background-color: green;
    flex-grow: 1;
}
#central_container{
    background-color: red;

    min-height: 60%;
    max-height: 60%;
}
#grid_container_static{
    overflow: hidden;      
}
</style>

The cells of the table are dynamic square tiles styled with the .tile class. If the total size of the grid exceeds the space within the grid_container_static, the excess is hidden behind the parent elements without affecting them. The user can drag the grid to reveal the hidden portions successfully.

To enhance this functionality, I've created a zoom function using JavaScript that adjusts the size of the grid tiles when the user scrolls the mouse wheel:

<script>
window.addEventListener("wheel", event => {
        const delta = Math.sign(event.deltaY);     
        
        if(delta < 0){
            current_tile_size ++;
        }else{
            if(current_tile_size > 1){
                current_tile_size --;
            }
            
        }
        var tiles = document.getElementsByClassName('tile');
    
        for(var i = 0; i < tiles.length; i++){
            tiles[i].style.width = current_tile_size+"em";
            tiles[i].style.height = current_tile_size+"em";
        }
    });
 </script>

While this script works as intended, it inadvertently affects the parents' heights when changing the tile size. My goal is to modify the zoom function to only impact the grid itself, ensuring that any excess remains hidden behind the parent elements without altering their dimensions. How can I achieve this?

Answer №1

To conceal overflow in the table when necessary, consider utilizing transform: scale. Since CSS Transform does not disrupt document flow, the DOM element will retain its original position and dimensions within the page layout.

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

Tips for comparing an input value with a data attribute

I'm having trouble getting my input value to match a data attribute within my code. Here is an example of what I am trying to achieve: HTML: <input value="" data-match="Training"> jQuery: var wrd = $('.js-search-input').data(' ...

Optimizing table resizing for improved speed in electron application

In my electron app, I've implemented the following JavaScript function to resize table columns: const resizerMouseDown = (e) => { let th = e.target.parentNode let startOffset = th.offsetWidth - e.x window.addEventListener('mousemo ...

Simple Solutions for Moving Containers Up in Angular When Clicked

In the left side container, I have a header and sub-header, while the right side container contains text. However, whenever I click on the sub-header to display text on the right side, both container positions shift upward, hiding the header text. I'm ...

Newbie inquiry regarding the setup and utilization of Bootstrap

I'm currently working on building a website and I decided to incorporate a bootstrap carousel. Initially, I had a dropdown button in the navbar along with a collapsible menu for smaller viewports which were functioning properly. However, when I added ...

Error: FullCalendar does not display a header for the timeGridWeek view when the dates fall

Currently, I am integrating fullcalendar 5.5.0 with Angular 10. After migrating from fullcalendar v4 to v5, I noticed an annoying issue where the header for the date before the validRange start is no longer displayed: https://i.sstatic.net/kvVUW.png Thes ...

The required validator in Mongoose is not being triggered by the function

I'm trying to use a function as a validator in a mongoose schema, but it doesn't seem to work if I leave the field empty. The documentation states: Validators are not run on undefined values. The only exception is the required validator. You ...

Issue with running CONCAT in query

I currently have: two different input options for searching. One is a text field where users can enter city, state, zip code, and type of business. The other is a drop-down menu where they can select the type of business they are looking for. My goal is ...

The property cannot be set for an undefined element in Jquery UI slider tabs

There seems to be some extra space at the bottom of the slider tabs between the navigators and content. Additionally, I am facing a challenge in making the page responsive as the content size does not adjust when I resize the window. To see the changes, I ...

Is the main content positioned below the sidebar on smaller screens?

In order to achieve a 250px col-2 sidebar with a col-10 main body that collapses into a top navbar and main content beneath it, my goal is set. However, I am facing an issue where the main content body goes underneath the sidebar when the screen size cha ...

"I'm interested in loading multiple Google Maps using a loop. Can you help

I am using a PHP while loop to generate multiple instances of a div class. Each time, I have different latitude and longitude values. Within each iteration of the loop, I initialize a new map on a separate div element to display the map. Below is the cod ...

Is it recommended to reset heading tag numbering while nesting them?

Consider an HTML book as an example (steering away from the typical blog post). Take a look at this code: <!DOCTYPE html> <html> <head> <title>The title</title> </head> <body> <h1>The title</h1&g ...

What is the best way to selectively add the x-ua meta tag specifically for Internet Explorer versions 10 and earlier?

I am facing a scenario where the x-ua code specified below is included in the header <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7" /> It functions correctly on Internet Explorer versions 10 and below. However, it causes certain feat ...

Flip the parent element's background image using CSS

I have encountered a challenging issue that I am hoping to find a solution for. Let's consider the following HTML structure: <div id="page"> <div id="menubar"></div> </div> Along with the CSS styling applied to it: #page ...

potential issues with memory leakage and browser crashes in three.js

Currently working on an app that features a spherical panorama photo with a jpg size of around 4Mb. Throughout the development process, I find myself constantly refreshing the page to see changes and browsing through various three.js example pages for insp ...

Automatically populating grids with Php

Here is a piece of HTML code I have: <div class="media row-fluid"> <div class="span3"> <div class="widget"> <div class="well"> ...

Expand and collapse divs using jQuery when a JavaScript do_PostBack link is clicked

Currently, I am in the process of developing a website called TheDigitalScale. One particular feature on the site involves using jQuery to create an expanding div that opens when clicked and closes with another click. <script type="text/javascript"> ...

Making alterations to the HTML code of a Tumblr theme in order to eliminate specific

Here is my custom Tumblr domain URL: http://intchauhan.com/ I would like to eliminate the "Follow intchauhan" and "tumblr." buttons located on the right side. Below is the HTML of the theme: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...

Create widget that is resistant to inherited traits

In our development process, we are crafting a widget designed to be seamlessly integrated into external websites. This integration involves the dynamic injection of a div element within the body of the page using Javascript. While the widget appears satis ...

Can a media source have a buffer that doesn't kick off with a key frame?

Is it feasible to utilize the media source extension to implement buffering such that buffers initiate with a typical frame rather than a key frame? For example, could the video be buffered frame by frame? (Even though that may not be the most practical a ...

Guidelines for creating a dynamic filter in Prisma js

I am looking to create a dynamic filter based on user input from the frontend. On mapping the data, I found that the object results appear like this: { id: '2', name: 'yuhu' } The keys 'id' and 'name' need to be dyn ...