Fine-tuning CSS layout based on perspective alteration

I am working with the following code:

function exportTableToExcel(tableID, filename = ''){
    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
    
    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
}
        .flex-container {
            width: 100%;
            height:98vh;
            display: flex;
            flex-wrap: wrap;
            background-color: DodgerBlue;
        }
        
        .flex-container > div {
            max-width: 100%;
            display: flex;
            flex-direction: column;
            background-color: #f1f1f1;
            margin: 10px;
            padding: 20px;
            font-size: 30px;
        }
        #path, #skills {
               /* will prevent resizing horizontally */
               /* resize:vertical; */
               width: 250px;
               max-width: 250px;
               min-width: 250px;
        }
        table, td, th {  
            border: 1px solid #ddd;
            text-align: left;
        }
        table {
            border-collapse: collapse;
            width: 100%;
        }
<div class="flex-container">
        <div style="flex-grow: 1">
            <input id="path" placeholder="cvs path"/>
            <textarea id="skills" placeholder="Key skills" rows="4" cols="50"></textarea>
        </div>
        <div style="flex-grow: 9">            
            <table id="tblData" >
                <tr>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Country</th>
                </tr>
                <tr>
                    <td>John Doe</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1cbcec9cfe1c6ccc0c8cd8fc2cecc">[email protected]</a></td>
                    <td>USA</td>
                </tr>
                <tr>
                    <td>Michael Addison</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="610c08020900040d21060c00080d4f020e0c">[email protected]</a></td>
                    <td>UK</td>
                </tr>
                <tr>
                    <td>Sam Farmer</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7c4d6daf7d0dad6dedb99d4d8da">[email protected]</a></td>
                    <td>France</td>
                </tr>
            </table>
            <button onclick="exportTableToExcel('tblData', 'members-data')">Export Table Data To Excel File</button>
        </div>
    </div>

The layout is exactly what I need on a full browser screen:

https://i.sstatic.net/7fS8s.png

However, when the view size is changed, it does not look as appealing. I would like two changes to occur when the flex layout splits into a vertical view:

  1. The "input" and "textarea" in the first flex item should expand horizontally to 90% of the flex view
  2. The font size of the data in the table should be adjusted to a smaller but still readable size

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

Answer №1

As mentioned by idfurw, it is essential to create responsive CSS. I have made some improvements to your existing CSS code.

function exportTableToExcel(tableID, filename = ''){
    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
    
    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
}
/* added */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.flex-container {
  width: 100%;
  min-height: 100vh; /* changed */
  display: flex;
  flex-wrap: wrap;
  background-color: DodgerBlue;
}

.flex-container > div {
  /* max-width: 100%;  can remove  */
  display: flex;
  flex-direction: column;
  padding: 20px;
  margin: 10px;
  background-color: #f1f1f1;
  font-size: clamp(1rem, 3vw, 2em); /* changed */
}

#path,
#skills {
  /* will prevent resizing horizontally */
  /* resize:vertical; */
  /* width: 250px; */
  /* max-width: 250px; */
  /* min-width: 250px; */
  width: 100%; /* added */
}
table,
td,
th {
  border: 1px solid #ddd;
  text-align: left;
}
table {
  border-collapse: collapse;
  width: 100%;
}
<div class="flex-container">
        <div style="flex-grow: 1">
            <input id="path" placeholder="cvs path"/>
            <textarea id="skills" placeholder="Key skills" rows="4" cols="50"></textarea>
        </div>
        <div style="flex-grow: 9">            
            <table id="tblData" >
                <tr>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Country</th>
                </tr>
                <tr>
                    <td>John Doe</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f656067614f68626e6663216c6062">[email protected]</a></td>
                    <td>USA</td>
                </tr>
                <tr>
                    <td>Michael Addison</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e23272d262f2b220e29232f2722602d2123">[email protected]</a></td>
                    <td>UK</td>
                </tr>
                <tr>
                    <td>Sam Farmer</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="493a2824092e24282025672a2624">[email protected]</a></td>
                    <td>France</td>
                </tr>
            </table>
            <button onclick="exportTableToExcel('tblData', 'members-data')">Export Table Data To Excel File</button>
        </div>
    </div>

Answer №2

Can you create the CSS code to make these elements responsive?

@media only screen and (max-width:768px)

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

I'm having trouble installing puppeteer

I tried running the command npm i --save-dev puppeteer to set up puppeteer for e2e testing. Unfortunately, an error occurred during installation: C:\Users\Mora\Desktop\JS\Testing>npm i --save-dev puppeteer > <a href="/cd ...

Explore in MegaMenu Pop-up

At my workplace, the internal web portal features a MegaMenu with a popup menu that includes a Search input field. The issue I am encountering is that when a user starts typing in the search bar and moves the mouse off of the megamenu, it disappears. It ...

Handling a change event for a mat-datepicker in Angular 7 can be tricky, especially when its value is tied to an optional input parameter. Let's dive into how to

I've recently started working with angular development and encountered a challenge with a mat-datepicker. The value of the datepicker is connected to filterDate using [(ngModel)] as an @Input() parameter. I have implemented a handleChange event that e ...

What is the most effective method to override parent styles while utilizing CSS Modules?

I'm currently using NextJS along with CSS Modules for styling purposes. One of my goals is to adjust the appearance of a component in different scenarios: When it's rendered normally on a page, utilizing props to specify className modifiers. W ...

Tips for halting all YouTube videos in a Reactjs environment

I am currently working with React.js and using Next.js. I have implemented a "YouTube video slider" and now I am looking for a way to stop all videos when a button is clicked. Can anyone provide guidance on how to achieve this? Below is the code snippet ...

Mocking a third-party callback function in Jest for method implementation

Utilizing Nest + Cognito for user authentication in an application, I have a method within my Authentication service that requires testing/mocking: async cognitoRegister(userPool: CognitoUserPool, { name, password, email }: AuthRegisterInput): ...

The width property is not being passed down to the table

I'm experiencing difficulties with the scaling of my body content. When the page is initially opened, it scales to 100%. However, when I resize the screen to make it wider, the content gets bigger but when I try to make it smaller again, it remains a ...

Parse a string in the format of "1-10" to extract the numbers and generate an array containing the sequence of numbers within the range

Looking to convert a string in the format "1-10" into an array containing the numbers within that range. Display the array on the screen using a for loop. For example, if "1-5" is provided, the resulting array should be: {1, 2, 3, 4, 5} Create a workflow ...

Exploring the power of async/await in combination with map or foreach

I am facing a challenge in retrieving multiple product prices from my database. I had initially thought of using the map or forEach methods to iterate through them and add up the prices to a variable as shown below: // Get Total exports.getTotal = (req,re ...

Creating a space for showcasing error messages in Angular and CSS

How can I display an error message min 3 char at the bottom of an input field when only 1 character is entered? Referencing this example: https://i.sstatic.net/Eujle.png Currently, the error message appears on the right side of the input field. https:/ ...

Using javascript to locate and substitute a word divided among multiple tags - a step-by-step guide

I need to utilize JavaScript to locate and substitute a word that has been separated into multiple tags. For instance, consider the following HTML code: <html> <body> <div id="page-container"> This is an apple. ...

How to Prevent Scrolling When Modal is in Use on Full Page JS

I am trying to achieve the functionality where when the modal is open, I want to prevent full-page scrolling in JavaScript. The issue arises when I open the modal and try to scroll, it ends up moving the content that's behind the modal, which is actua ...

Learn how to retrieve URL parameters using HTML code

I would like to update the URL without refreshing the page as I am using an AJAX function to refresh a specific div. The issue I am encountering is that when the div is reloaded via AJAX, it does not recognize the URL parameter. Below is my code (I have a ...

Issue with JQuery's click and submit events not triggering, but change event is working fine

My webpage has a dynamic DOM that includes add and save buttons to interact with elements. Each row also has a remove option for deletion. When a user logs in, the controller redirects them to their homepage in the codeigniter PHP framework. This controlle ...

What is the purpose of specifying http://localhost:3000 when accessing API routes in Next.js?

I created an API route within the pages directory of my NextJS project. It is functioning properly as I am able to retrieve data by directly accessing the URL like http://localhost:3000/api/tv/popular. My goal is to fetch this data using getStaticProps and ...

Experiencing difficulty adjusting the width of a Tumblr post with JavaScript or jQuery?

Calling all coding experts! I've been working on customizing a Tumblr theme, and everything is looking good except for one issue. I'm struggling to adjust the width of photos on a permalink (post) page. Check out this link: You'll notice t ...

Manipulating checkboxes with Jquery

I have set up a scenario with two divs and two checkboxes. When the first checkbox is clicked, the first div will appear. Subsequently, if the second checkbox is clicked, the second div will appear below the first div. I initially styled both divs. Howev ...

Could it be questionable XHTML originating from a conventional Haskell library?

Currently, I am working on resolving an issue with a program that generates XHTML in Haskell from UTF-8 text. The program is supposed to turn strings of text into valid XHTML entities, but it seems to be failing in doing so. I have imported Text.XHtml.Tran ...

The content of the string within the .ts file sourced from an external JSON document

I'm feeling a bit disoriented about this topic. Is it feasible to insert a string from an external JSON file into the .ts file? I aim to display the URLs of each item in an IONIC InAppBrowser. For this reason, I intend to generate a variable with a sp ...

What could be causing the computed property in Vue 2 component to not return the expected state?

I'm encountering an issue with my Vue component where it fails to load due to one of its computed properties being undefined: Error: Cannot read properties of undefined (reading 'map') Here is the snippet of the computed property causing ...