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

What could be causing the Php Media Gallery to malfunction?

I am currently working on setting up a video/image gallery to simplify the process of uploading videos/images. This gallery will include thumbnail images of the videos/images along with a brief description. When the thumbnail is clicked, the image/video wi ...

Combine linear and radial background effects in CSS styling

I am trying to achieve a background design that includes both linear and radial gradients. The linear gradient should display a transition from blue to white, while the radial gradient should overlay a polka dot pattern on top of it. I have been following ...

What causes divs to be interspersed among other divs when Float is enabled?

I am looking to create a layout for 4 sections, similar to a table, utilizing only divs and CSS. The intended output is this: Logo-----------Info Business-------Client I initially thought it would be simple by using the Float property. However, when I se ...

Applying CSS to an iframe using JavaScript: A Step-by-Step

I have an Iframe editor and I am trying to change some CSS inside the editor. However, when I attempt to apply the CSS, it does not affect the styles within the Iframe. <div id="editor" style="flex: 1 1 0%;"> <iframe src="https://editor.unlay ...

When using the * selector in jQuery on Chrome, it targets and selects scrollbars

Here's the code I'm currently using: $("*").bind("mousedown.sg", { 'self':this }, this.sgMousedown); This code binds an event listener to all elements on the page, and it functions properly in most browsers except for Chrome. In Chrom ...

What could be causing the sluggishness in my jQuery script that checks for required input fields?

My goal is to utilize jQuery to check for required input fields in browsers that do not recognize the required HTML tag. Below is the jQuery script I am using. $('div').on('submit', '#myform', function(e){ e.stopProp ...

Form submission requires a checkbox to be checked

I have been searching for a way to make checkboxes required. Is there a method similar to using required="required"? Currently, I generate my checkboxes in the following manner and would really appreciate any guidance on this topic. It's crucial for m ...

basic handler in expressjs using the PUT method along with jQuery ajax

I am currently developing a web application utilizing a REST API for server communication. The backend is built with Node.js using Express.js. One issue I am running into is the inability to read the request body in PUT requests. Below is my client-side co ...

How can I rename attribute values in a dropdown menu and ensure they work properly?

I'm facing an issue with my code. How can I store the option values in a database when they have numbering like value="1" or value="2"? Can I change it to something like value="1000" and have the other select box change to value="250" when selected? ...

Irregular word spacing observed in HTML code

The alignment of text on my website is causing some spacing issues that I can't quite seem to resolve: It's an asp.net page, and I've attempted a couple of potential solutions: CSS .optionClosed { font-size: large; ...

Using Jquery Mobile to make an AJAX POST request with XML

Is it possible to use this code for XML parsing? I have successfully parsed using JSON, but there is no response from the web service. This is the status of the webservice: http/1.1 405 method not allowed 113ms $j.ajax({ type: "GET", async: false, ...

Problem with Chrome Compatibility for Bootstrap Carousel

My webpage features a carousel implemented as a slider. It seems to be working fine in Firefox and mobile browsers, except for Chrome where it doesn't show up at all. I can't seem to figure out what's causing the issue. Here is the syntax I& ...

Close specific child python processes as needed, triggered by a jQuery event

Having trouble managing child processes independently without affecting the main parent process in a web client using jQuery? Look no further. Here's my scenario: I've got a Flask server hosting a basic webpage with a button. Clicking the button ...

What is the best way to overlay text onto a background image using Material UI's Card and CardMedia components?

Using the card component, I have successfully added a background image. However, I am facing difficulty in figuring out how to overlay text on top of this image. If anyone has suggestions or alternative methods, please feel free to share! <Card> ...

Is the Mini Cart button in Woocommerce not aligned properly?

My website was functioning perfectly until yesterday. However, after updating some plugins, the Mini Cart dropdown button started to display in a weird and misaligned manner. Prior to the plugin updates, the button had the following style: background-col ...

Using the feColorMatrix SVG filter in CSS versus applying it in JavaScript yields varied outcomes

If we want to apply an SVG filter on a canvas element, there are different ways to achieve this. According to this resource, we can apply a SVG filter to the CanvasRenderingContext2D in javascript using the following code snippet: ctx.filter = "url(#b ...

Ways to incorporate a focus event into a template

I'm currently working on implementing autocomplete functionality in the search box on my homepage. To achieve this, I have included an onfocus event for the template to execute a jQuery command targeting the source elements. The method I used to add j ...

How can jQuery incorporate additional selection criteria for a parent element?

How can I apply a specific criteria to a node that has been selected using jQuery? let objDIV = $("#selindividual").parent(); After retrieving the DIV, I want to target the following: button:contains(\"Submit\") If I had to do this in ...

Customizing HTML Select Elements

Can the HTML Select attribute be customized to have a flatter appearance? Although I can set the border to be 1px solid, the dropdown part still appears 3D and unattractive. ...

Utilizing the position relative property with Firefox browser

Similar Question: Is Firefox compatible with position: relative on table elements? Check out this example: a full-width menu formatted as a table with ul dropdown menus. Everything works as expected in IE and Opera, but in Firefox the dropdown uls ex ...