Are the dimensions of <TD> and <table> not displaying properly?

I've encountered a peculiar issue that I need help with.

Here is the Fiddle link: http://jsfiddle.net/H3W4X/

If you want to view it in fullscreen: http://jsfiddle.net/H3W4X/embedded/result/

This is the code snippet causing trouble:

<div id="workspace"> 
       <table id="leds" >
            <tbody id="leds_body">
            </tbody>
       </table>
</div>

Here's the CSS associated with this code:

#workspace{
position:absolute;
left:200px;
width:760px;
height:600px;
background:#0FF;
float:left;
overflow-x: auto;
overflow-y: auto;
background-image: url("bg.png");
background-repeat: repeat-x;
}

#leds
{    
position:relative;
left:10px;
margin-top: 50px;
margin-left:50px;
margin-right:50px;
border-collapse: collapse;
border: 2px solid black;
}

And adding jQuery behavior to it:

var WH=10;
$(function(){
    $("#zoom-in").click(function(){
        $(".LED, .NOT_LED").width((WH+1)+"px").height((WH+1)+"px");
        WH=WH+1;
        });

    $("#zoom-out").click(function(){
        $(".LED, .NOT_LED").width((WH-1)+"px").height((WH-1)+"px");
        if (WH==5) WH=5;
        else WH=WH-1;

});
});

My goal is to be able to zoom in/out of my table by adjusting the size of <td>. However, when I try to zoom in, the table grows on the width only up to 656px, then the width remains static while the height continues to grow. Upon inspecting this behavior in Chrome, I noticed that the table has a fixed width of 656px. How can I make sure both width and height adjust accordingly without being constrained to a specific value?

Answer №1

The reason for the issue is that your table with id #leds is set to default width: 100%, causing the td elements to adjust according to the width. While a simple CSS solution wasn't found, you can manually set the width by clicking on the + or - signs:

$(function(){
    $("#zoom-in").click(function(){
        $(".LED, .NOT_LED").width(WH+1).height(WH+1);
        $('#leds').width($('#leds_body tr:eq(0) td').length * WH);
        WH=WH+1;
        });

    $("#zoom-out").click(function(){
        $(".LED, .NOT_LED").width((WH-1)+"px").height((WH-1)+"px");
        $('#leds').width($('#leds_body tr:eq(0) td').length * WH);
        if (WH==5) WH=5;
        else WH=WH-1;

});

http://jsfiddle.net/H3W4X/3

http://jsfiddle.net/H3W4X/3/embedded/result/

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

How can you make divs adapt to screen resizing in a similar way to images?

In my REACT project, I am faced with the challenge of positioning three divs next to each other, with a small margin between them, and ensuring they are horizontally centered on the screen. As the screen width decreases, I need the right-most div to move ...

Looking for a drag-and-drop solution using Vanilla Javascript, no need for jQuery

Looking for assistance with creating a click-and-drag solution for a background image using Vanilla Javascript. I came across a jQuery solution on Codepen, but I need help translating it into Vanilla Javascript. Draggable.create(".box", { ...

Scrolling Down on a Jquery Login Page

I am currently utilizing JQuery version 1.4.2. My objective is to allow the user to scroll down to the login form by clicking on the 'login' option in the top menu, similar to Twitter's design. The implementation works impeccably with insert ...

Is there a way for me to manually designate certain domains with the rel="follow" attribute while assigning all other external links with the rel="nofollow" attribute?

I'm working on developing a community platform similar to a social network. I've implemented a code that automatically makes all external links nofollow. However, I would like to create a feature that allows me to remove the nofollow attribute f ...

Footer overlapping occurs on a single page

My webpage is having an issue where the footer is overlapping. It seems to be fine on all other pages except for this one. I would prefer not to make any changes to the footer since it's working correctly on other pages. Is there a way to adjust the C ...

Customizing the styling of a TextField component in ReactJS using material-ui

I am currently working with Reactjs and material-ui. I am looking to apply some custom styles to a TextField using css. Specifically, I would like to change the color of the TextField underline and label when the input is clicked. Although I know it can b ...

Scalable vector graphics require adjustments in scaling and translation, with variations between Chrome and Firefox browsers

I have an SVG diagram with some yellow points represented as circles. <html> <title>Yellow circles</title> <body> <svg version="1.1" id="Слой_1" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" ...

Trying to organize JSON data by multiple parameters using jQuery

Regarding the topic discussed in this thread; I have successfully managed to sort an Array of JSON Objects by two fields. Additionally, the discussion mentions: "To include additional columns for sorting, simply add them to the array comparison." // ...

The left and right DIVs are not automatically adjusting to the height of the container

I am currently working on a grid layout consisting of 9 div tags, creating 3 rows with 3 divs in each row. Within this grid, each div is supposed to have a background image, except for the second div in the second row. My main challenge lies in getting th ...

Sticky positioning causes elements to stick to the window as the

https://i.stack.imgur.com/nv3vU.png I am facing an issue with a position sticky block that can vary in height relative to the window size. Sometimes, the block is taller than the viewport, making it impossible to scroll to see all the content. Is there a ...

What is the solution to the error message "cannot find specified file or directory, lstat 'scss/'"?

I am currently following a tutorial on YouTube here where the instructor is demonstrating how to run an npm script "sass" file using the terminal. When I try executing the command npm run sass, it gives me an error message: Error: ENOENT: no such file o ...

The selection button's threshold

Welcome to my website design project! I have implemented image buttons for my web page and want to restrict the number of images a user can select. If a user tries to navigate away after selecting more than 3 images, I wish to display an alert message. Her ...

Automatically update div content using AJAX in a different approach

In my situation, I am facing a unique challenge compared to other queries. I have a div element with the following code <div id="ondiv"><?php ?></div> Within this PHP section are details of people who are currently online. Ideally, when ...

Unable to eliminate border from image within label

The following code generates a border that appears to be approximately 1px thick and solid, colored grey around the image. Despite setting the border of the image to none, the border still remains. Here is the code snippet: <label> <img styl ...

Maintain only specific elements in jQuery by filtering out the rest

Here is a scenario with a page layout to consider: <div id="page-container" class=""> <div id="scroller"> <!-- This page should be removed --> <div id="page_1" class="pagina"></div> <!-- These pages should be kept --&g ...

A guide to displaying dropdown values above a modal

I have encountered an issue while using a dropdown inside a modal window. The problem is that not all the dropdown values are visible, as the overflow part gets hidden. I am looking for a solution to keep the dropdown value at the top and prevent it from b ...

What could be causing my (multi) page not to load in JQM?

Currently working on a hybrid app using jQuery Mobile, I have 2 separate files which contain a total of 3 pages. In File 1: Page A In File 2: Pages B and C When I navigate from page A to page B by clicking on the link, the page loads successfully. Howe ...

Styling with CSS using the em unit to make an image half the size of its parent div element

I'm struggling with resizing an image within a div using the em size unit. I want the image to be half the size of its parent div, so I set both the width and height CSS properties of the image to 0.5em. However, when looking at the code below, you c ...

What is the best way to navigate back on a button click in jquery AJAX without causing a page refresh?

Is there a way to navigate back without refreshing the page? I am fetching data dynamically using AJAX, but when I try to go back using the browser button, it takes me all the way back to the starting point. Let's look at the situation: 3 Different ...

Tally each div individually and display the count within each div, instead of showing the total count across

I have come across various solutions that show the total number of certain special divs, such as: $('.someclass').length However, I am facing a different challenge. I want to sequentially count each div with a numerical sequence. For instance, ...