spacing between image tiles as you zoom in

My website features diagrams consisting of 9x9 tiles arranged in columns and rows. The final result should look like this:

https://i.sstatic.net/694EH.png

In the image above, the tiles are closely packed and appear as a single unit. However, when users zoom in, black and white lines start to appear for some unknown reason.

In IE11, random black and white lines can be seen in various places.

https://i.sstatic.net/1eHIo.png

Even in Chrome, a grid-like pattern emerges.

https://i.sstatic.net/jG3gY.png

All images are loaded from a single png file with each cell being restricted to 31x31 pixels in width and height.

https://i.sstatic.net/8QVAT.png

The table is created using several <div> html elements.

<div class="my-table">
  <div class="my-row">
    <div class="my-cell my-cell-empty-center"/> 
    <!-- repeated 9 times -->
  </div>
  <!-- repeated 9 times -->
</div>

The CSS code removes borders and spacing between elements.

.my-table{
  display:table;
  width:auto;
  border:0px;
  border-spacing:0px;
  padding: 0px;
  border-collapse: collapse;
}

.my-row{
  display:table-row;
  width:auto;
  height: auto;
  clear:both;
}

.my-cell{
  float:left;/*fix for buggy browsers*/
  display:table-column;
  width:31px;
  height:31px;
  background: url(sprites.png) no-repeat;
}

There is additional CSS to specify the correct section of the image for each cell, which may vary.

.my-cell-black{background-position: 0 -93px ;}
.my-cell-white{background-position: -62px -93px ;}
.my-cell-empty-center{background-position: -31px -31px ;}
.my-cell-empty-dot{background-position: -31px -93px ;}
.my-cell-empty-left{background-position: 0 -31px ;}
.my-cell-empty-top{background-position: -31px 0 ;}
.my-cell-empty-right{background-position: -62px -31px ;}
.my-cell-empty-down{background-position: -31px -62px ;}

Any thoughts on what might be causing these issues?

Answer №1

Whenever the user adjusts the zoom level, calculations take place based on the percentage of the zoom. Due to this approach, it is common for non-integer values to be generated, leading to rounding off of pixel values. This rounding off can sometimes result in 1px lines being displayed, similar to what is shown in your screenshots, as the total sum of rounded values may not match the total sum of the container containing these elements. Unfortunately, there isn't much that can be done to avoid this phenomenon.

Answer №2

Update: A New Approach After Almost 5 Years.

Soon after posting my inquiry and reviewing the feedback, I made the decision to transition to utilizing SVG for everything.

  • SVG's vector-based nature allows for seamless resizing without loss of quality.
  • You can embed SVG directly within your HTML markup, eliminating the need to import image files separately.
  • Frameworks like Angular (and potentially Vue and React) offer dynamic rendering capabilities for SVG.

Instead of piecing together multiple images to create a long line, I now simply draw the line using SVG.

https://i.sstatic.net/S0eE3.png

Here are some additional performance tips for those embarking on similar projects:

  • Add pointer-events="none" to your SVG nodes to improve processing efficiency when interacting with them. Consider consolidating click event handling into a single listener instead of numerous individual ones for better overall performance.
  • If you're using Angular, implementing an OnPush change detection strategy can help prevent unnecessary re-renders of your components.

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

Enhancing Image Quality in Internet Explorer 10

Here is my current situation: I am working on a web page with a responsive design. The layout of the page consists of two vertical halves, and I intend to display an image (specifically a PDF page converted to PNG or JPG) on the right side. The challenge ...

What steps can I take to ensure that a JavaScript function does not execute when a DOM element from an array has already been chosen?

I am facing an issue with a script that dynamically changes the header based on the selected bubble in an array. The problem arises when the user clicks on the same bubble that is already selected, causing the JavaScript function to run and temporarily cha ...

Is there a way to prevent jQuery's .after() from modifying the HTML I'm trying to insert?

Trying to divide a lengthy unordered list into smaller segments using the following code: $('.cList').each(function() { var thisList = $(this).find('li') var thisLen = thisList.length for(var x=0;x<thisLen;x++) { ...

Once the <a> element is clicked, ensure that the function finishes executing before attempting to click/process it again

Utilizing jQuery.get for AJAX requests, I trigger a server request when the user clicks on the <a> element. The response is then used to update the content within the <div id='aaa'>. However, if the user clicks on the <a> rapid ...

Checking the validity of user input statements

When 2 conditions are met, both error links and messages will display on top of each other. If an input is 0, the validation statement for empty inputs will also trigger. Additionally, if one input is not numeric but the other is, PHP will calculate the va ...

having difficulty setting up tabs using uib-tabset

I have been experimenting with dynamically creating tabs using uib-tabset. Each tab is supposed to contain a different form, but the issue I am facing is that the textbox from the first form is being overwritten by the newly generated tab. When I enter d ...

What is the best way to horizontally align three animated progress bars alongside images?

Check out this jsfiddle that shows a vertical alignment of the progress bars. How can I modify it to align them horizontally and centered? https://jsfiddle.net/bLe0jLar/ .wrapper { width: 100px; height: 100px; } .wrapper > #bar, #bar2, #bar3 { ...

The background color of social media links spills over onto other links, creating a messy overlap

I have been trying to confine the teal hover effect within the boundaries of my social media links. Despite adjusting padding, heights, and widths using CSS properties, the hover effect still extends beyond the right border. Here is how it appears without ...

Can you please explain the significance of this error for me?

I'm attempting to showcase specific elements from an array in my code. <?php $data = array( 1000 => array( "id" => 1000, "number" => 2380, "name" => "CS2", "instructor" => "Chen", "rating" => null ), 1001 => a ...

In AngularJS, the process of replacing text using a filter can be achieved by following

Currently in the process of learning Angular, but I've hit a roadblock and can't seem to find a solution. I have a website that provides USPS shipping options, and I need to replace the default text with my own. The vendor's option shows &ap ...

Receiving partial data through the API

My PHP API seems to be experiencing issues when I send data to it using either a post or get request. The strange thing is that the API receives only half of the data. This API functions perfectly fine on localhost, but encounters errors when used on the p ...

Wrap text elegantly around your images with Flex Mobile

Looking to develop a component for a Flex Mobile app that will allow me to have text wrapped around an image, similar to what you see in articles or blogs. In HTML, this can be achieved with a tag like: <image align='right' /> associated t ...

Several levels piled one on top of the other

I'm in the process of designing a section for a webpage using Bootstrap 3.0, and I want to layer three divs or sections on top of each other. The stacking order should be as follows: background "squares," footer, and foreground "squares" with images. ...

JavaScript Processing Multiple Input Values to Produce an Output

Hello, I am working on creating a stamp script that will allow users to enter their name and address into three fields. Later, these fields will be displayed in the stamp edition. Currently, I have set up 3 input fields where users can input their data. He ...

Grid X Transformation 3: Dynamically alter grid cell background based on value (no need for CSS classes)

While working with GXT2, it was possible to dynamically change a cell's background color using the GridCellRenderer's render method. However, in GXT3, this feature no longer exists. The suggested approach is to utilize a GridViewConfig and overri ...

Attempting to visually create a line using a bullet in CSS

I found a beautifully designed CSS header title on another website that I fell in love with. I want to replicate the same look, but without using CSS tables like they do on that website. Here is an image of what I am aiming for: https://i.sstatic.net/qeoS ...

"Preventing the propagation of a click event on an anchor tag with

Is there a way to prevent the parent anchor from executing its href when a child element is clicked, despite using stopPropagation? Here is the markup provided: <div id="parent"> <h5>Parent</h5> <a id="childAnchor" href="https:// ...

Toggle the visibility of 2 Form Fields by checking the Checkbox

Hi, I am trying to display two form fields when a checkbox is selected. These fields are required, so they should only be displayed when the checkbox is checked and should be mandatory. However, I am facing issues with hiding the fields when the checkbox i ...

Tiny cutout circle nestled within a larger circle, subtly placed in the bottom right corner using Bootstrap

In my JavaScript code, I have created an array of images arranged in a row on the webpage using the split method. The images are displayed in circles. However, I now need to add a smaller circle cutout at the bottom right of each larger circle to showcase ...

Unable to insert JSON data into modal

I am facing an issue with appending Descriptions into modals after fetching data through axios. Each div contains a Category, and clicking on it should open a corresponding modal displaying the Description. Although I can see the Descriptions in the conso ...