Align the dimensions of the table to match with the background image in a proportional

Seeking a contemporary method to match a table with a background image, ensuring all content scales proportionally. Mobile visibility is not a concern for this specific project. Using Wordpress with a starter bootstrap theme. Check out the code on jsfiddle: https://jsfiddle.net/atomikdog/6m5h2wa0/26/

.entry-content {
  background-image: url("https://i.postimg.cc/R0rR2qmp/bg-report-test-1500x2023.png");
  background-size: 100% auto;
  background-repeat: no-repeat;
  min-height: 1700px;
  margin: 0 0 0 0;
  border: 1px dashed yellow;
}
.test {
  padding: 0 0 0 0;
  width: 77%;
  margin-top: 37px;
  border: 1px dashed cyan;
}
.row {
  border: 1px dashed green;
}
table {
  width: 100%;
  padding: 0 0 0 0;
  margin: 0 0 0 0;
}
td {
  font-size: 2vw;
  border: 1px solid red;
}
.col53 {
  width: 53%;
}

Answer №1

Your reasoning is solid, except for the issue with the margin at the top. This occurred because a fixed value was used instead of a relative one like a percentage. Adjusting the margin of test to margin-top:6%; appears to provide better results. You may also want to customize the image to better suit your requirements.

Answer №2

Implemented a unique approach utilizing vw units. Initially, the background image seamlessly integrates into .entry-content at a 100% scale. The .tableContainer is sized at 75% to correspond with the background image table, calculated using 75vw. The height of the container is set based on the aspect ratio of the image. Additionally, a media query is employed to establish a maximum width and height...

.entry-content {
      background-image: url("https://i.postimg.cc/R0rR2qmp/bg-report-test-1500x2023.png");
      /* image aspect ratio is 1.349 */
      background-size: 100% auto;
      background-repeat: no-repeat;
      margin: 0 0 0 0;
      height: calc(100vw*1.349);
      max-width: 1200px; /* from wordpress */
    }
.tableContainer {
      padding: 0 0 0 0;
      width: 75vw;
      height: calc(75vw*1.349);
      margin-top: 6%;
    }
@media only screen and (min-width: 1200px) {
    .container-fluid.test {
        width: 900px;
        height: calc(1200px*1.349)
    }
}

Following that, the heights of the table rows were determined by establishing either fixed pixel heights for maximal size or utilizing vw units when the window is smaller...

.test tr {
    height: 48.96px
}
@media only screen and (max-width: 1200px) {
    /* When 100 vw = 1200px; 100 vh = 1200px * 1.349 = 1618.8px; */
    /* When 100vw, table is 75vw 75vh */
    /* 48.96/1200 = 0.0408 */
    /* 4.08vw doesn't work so use an eyeball number */
    .test tr { height: 3.75vw; }
    ...

This solution may seem unconventional. Will take some time to review before finalizing it as a definitive answer.

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

Is there a way to send decimal values from a view to a controller using Vue.js?

I am encountering an issue when trying to pass decimal values from the view to the controller using Vue.js. Only decimal values seem to be arriving as NULL, while integer or string values work fine. Below is the code snippet: salvarProdutos: function ( ...

Tips for maintaining position when refreshing a web page within a scrolling table

Recently, I came across a helpful tutorial on how to create a table with a fixed header and scrollable body. You can find it here. While the tutorial worked perfectly for me, I encountered an issue when trying to refresh the webpage and maintain my positio ...

How can we efficiently load a JSON file from a local path into an HTML document in a way that is compatible with all browsers?

I am attempting to retrieve JSON data from a local path and display it on a basic HTML page. I have tried various methods such as fetch, ajax in order to load the data and update the corresponding values on the web page. The goal is to host this page so t ...

Retrieve all tags that come after a specific <a> tag inside a <td> element using Scrapy

Looking to extract information from this specific webpage using Scrapy: My goal is to retrieve the summaries from the GeneCard, which are structured in HTML as follows: <td> <a name="summaries"></a> <br > <b>Entr ...

Is there a way to customize Firefox's default styles similar to Chrome's?

Can you change the default styles of Firefox to match those of Chrome? ...

Having trouble with compiling SCSS code

While diving into the world of SCSS, I decided to compile my SCSS into CSS using npm. So I entered npm run compile: sass as defined in my package.json as follows: "scripts": { "compile:sass": "node-sass sass/main.scss css/style ...

JavaScript: How to Build a Digital Grocery List with Browser Storage

Struggling with a tough exercise question, I could use some help deciphering it. https://i.stack.imgur.com/V5he2.png Here is how I've started the code: <!DOCTYPE html> <html> <head> <title></title> <script> fun ...

I am encountering an issue where my codeigniter controller is unable to load my model

Below is the code for my controller: defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('User_model') ...

How can you position text to the right of an image using CSS?

Trying to right-align text next to an image; CSS .p1 { position: absolute; width: 100px; height: 50px; top: 40%; left: 70%; } HTML <img src=../images/diagram1.png alt="Diagram"/> <span class="p1">This is a tes ...

Creating dynamic templates for table rows in AngularJS directives

Is it possible to dynamically load an AngularJS Directive templateUrl while working within a table? In my scenario, I have the following HTML structure where I am repeating a tr element with a fw-rule directive: <tbody> <tr ng-repeat="rule in ...

`Need help setting the active class for a bootstrap navbar using Angular JS?`

In my bootstrap navbar, I have the following menu items: Home | About | Contact I'm looking to assign the active class to each menu item based on the current angular route. Specifically, how can I set class="active" when the angular route is at # ...

Creating custom elements for the header bar in Ionic can easily be accomplished by adding your own unique design elements to the header bar or

I'm a beginner with Ionic and I'm looking to customize the items on the header bar. It appears that the header bar is created by the framework within the ion-nav-bar element. <ion-nav-bar class="bar-positive"> <ion-nav-back-button> ...

Working with radio buttons in a loop using PHP

I am facing an issue with a loop that iterates 3 times. In the loop, there's an HTML form containing radio buttons and I am processing the input using PHP. However, when echoing the form data, it does not display the correct values. Is there something ...

Steer clear of altering line spacing in CSS

Here is the HTML structure that I am working with: <div id="id1"> <h1>my name </h1><h3><a href="mailto:myemail_id"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff92869a929e9693969bbf878685d19 ...

Tips to detect a specific animation completion on an element?

How can I ensure that a specific animation ends when multiple animations are triggered on an element? My scenario involves an overlay song list that appears when a list icon is clicked. The challenge lies in closing the menu smoothly. I have implemented a ...

Generating various fields within a single row

I am in the process of creating a dynamic form that should generate two new fields in the same line when the user clicks on the plus icon. Currently, the code I have only creates a single field. I attempted to duplicate the code within the function, but i ...

Choosing an option in Angular 2 based on a specific condition

My question is about a select element: <select id="position"> <option *ngFor='#contactType of contactTypes' [attr.value]='contactType.contactTypeId'> {{contactType.description}} </option> </select ...

The hyperlink tag within the overlay div is unresponsive

I'm facing an issue with my overlay div (rb-overlay) that pops up when users click on a page option. The overlay takes up the entire page and includes a close button in the top right corner. However, I've noticed that the link at the end of the t ...

My experience with jquery addClass and removeClass functions has not been as smooth as I had hoped

I have a series of tables each separated by div tags. Whenever a user clicks on a letter, I want to display only the relevant div tag contents. This can be achieved using the following jQuery code: $(".expand_button").on("click", function() { $(th ...

HTML File Path for C Drive

I am a beginner with HTML and I'm facing an issue regarding displaying an image located at "C:\Users\Jas mine\folder\landscape.jpg" in HTML. I have tried various solutions posted by others but none of them seem to work for me. Can ...