Adjusting the height and width of tables or divs to match the size of the background

I have a div with a large image as the background, which needs to be displayed once at the maximum size allowed by the container while maintaining aspect ratio. The image can have any aspect ratio and so can the resizable container. I was able to achieve this using the following CSS:

background-size:contain;
background-repeat:no-repeat;
background-position: center center;
width:100%;
height:100%;
background-image: url("path/to/img");

Above this image, I need an 8x8 table layout that scales along with the background image.

In my jsfiddle example, you can see the image working correctly (try resizing the window), but I am unsure how to make the table always scale directly over the image (the goal is for field A1 to consistently mark the same spot on the image, regardless of its size, aspect ratio, or the container's aspect ratio).

https://jsfiddle.net/15uovq7L/4/

If there is no CSS/HTML solution to this issue, I am open to a jQuery/JavaScript solution.

Answer №1

https://jsfiddle.net/15uovq7L/5/

Include padding-top: 46%; inside .tlorisOgledNacrta.

The calculation for 46% is the image height multiplied by 100 and divided by the image width.

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

Render real-time webpage elements depending on the URL parameter (Using Parse Cloud, Express, ejs)

As a newcomer to programming, I have embarked on a project to create a web app using Parse.com Cloud Code and Express. The structure of my project is as follows: app.js (Containing Express related codes) views/hello.ejs (Template file) main.js (Clo ...

Ways to monitor and manage the most recent asynchronous request

My AngularJS controller is handling asynchronous calls to a service that returns promises. $myService.getData(ctrl.state) .then(function(data) { updateInterface(data); }); Issue arises when the promises return out of order, resulting in interface dis ...

Instructions for altering the hue of a canvas square when the cursor hovers over it

I want to implement a feature where the color of a tile changes when the user hovers their mouse over it, giving it a whitened effect. The tileset I am using consists of 32x32 tiles. Below are the scripts for reference. MAP.JS function Map(name) { ...

What is preventing me from manipulating this Object outside of the ngOnInit() function?

I've been working on a project that involves fetching data from the server and manipulating it within the .ts file. However, I seem to be facing a common issue related to Typescript/angular concepts that I'm struggling to grasp...I would really a ...

Having difficulty retrieving data in mongodb using category id

Currently, I am attempting to sort and filter my pets based on categories. The pets are modeled as follows: const Pet = mongoose.model( 'Pet', new Schema({ name: { type: String, required: true, } ...

What steps can I take to stop full-width images from stretching to fit the entire body size when placed within a flex container?

I'm having trouble with my layout - specifically, I have one container with four columns. It looks fine when I manually set the image sizes in each column, but I want to use percentage widths for more flexibility. However, when I do this, the images e ...

Use jQuery.on to load the href into a div element

Is there a way to modify the jQuery load function in order to load a PHP page into a div using .on method? Currently, I am loading different PHP pages into a "modal" div using .load. However, each PHP page calls jQueryUI datepicker and when the content ...

Conceal the .dropdown-backdrop from bootstrap using solely CSS styling techniques

Is there a way to hide the .dropdown-backdrop element from Bootstrap for a specific dropdown on a webpage using only CSS? I found a solution that involves Javascript, you can view it on JSFiddle here. However, I am hoping to achieve this without relying o ...

What steps can I take to ensure that images appear in the correct size when converting an HTML page to a PDF format?

I have noticed an issue with my web page when trying to print it as a PDF. Everything displays correctly until I reach a page with images. Strangely, the images appear with the correct width but an incorrect height in the PDF preview. The HTML code causin ...

Is it possible to automatically select a file and upload it to a specific server? If so, how can this

Hey there! I'm looking for a code snippet that allows me to automatically select a file and upload it to a specific link. Any ideas on how to accomplish this task? Here is the HTML code: <html> <head><title>Uploading</title>& ...

What is the best way to resize a primefaces inputTextArea to match the length of the

I am currently working on improving the appearance of <p:inputTextArea/>. When the page loads, I notice: And when I click on that TextArea: Here is the code: <p:inputTextarea rows="6" value="#{bean.object.value}" style="width: 100%;" /> Is ...

Issue with jQuery sortable serialization when dynamically adding content is not being recognized

I've been attempting to re-order a list through ajax on sortable update. However, when I add a new item to the list via ajax after the sortable has already been initialized upon page load, it fails to recognize the new item with the "serialize" functi ...

Safari is currently unable to process XML responses

Here is the code we have attempted, please review and provide feedback. function GetXmlHttpObject() { var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { ...

Discover the magic of unlocking XML content with the power of XSL!

Hello, I am currently working on transforming an XML archive using an XSL archive. My goal is to generate a table displaying the content of the XML, but I am encountering difficulties in showing the values of two columns named "complexity" and "subject". B ...

I'm having an issue where my footer is getting cut off when I resize the browser and start side scrolling. Can

I designed a webpage with a footer that contains another div holding centered content. The footer is supposed to span the entire width, while the inner content div is set to 960px with a margin auto to center it. <footer> <div class="footer-in ...

Utilizing modal functionality for seamless integration of new data into mui-datatable

When trying to add a new data entry using a modal box, I encountered an issue where the new data was not being added to the datatable. Is there a solution for this problem? Below is the code snippet I used: let id = 0; function createData(name, provider) ...

Arranging divs with CSS positioning

I struggle with positioning divs, especially in this particular situation. I am attempting to position boxes in the following layout: _ ___ _ |_|| ||_| _ | | |_||___| Is there a way to avoid manually defining pixel positions for each box and ins ...

Adding the victory chart in react-native slider causes performance issues, as the slider becomes laggy and there is a delayed reflection

When I use a slider in my application without including a Victory chart, the slider functions smoothly with no issues. However, integrating the slider with the Victory chart causes lag and delays in updating the state value on screen. For more detailed in ...

Can you explain the distinction between mutation and action?

Can you explain the rationale behind Vuex having both "actions" and "mutations?" I can see the point of components not directly modifying state, but it seems redundant to have actions trigger mutations to update the state. What sets "actions" apart from ...

CSS layout with percentage values breaks when viewed on iPad

Currently, I am in the process of developing a website according to a client's requirements. The site works perfectly on OSX Safari, Firefox, and Chrome but has not been tested on PC yet. However, it breaks quickly when accessed on an iPad and is comp ...