Ways to modify div content depending on the size of the screen

When the screen size becomes small, my goal is to modify the content within the row divs of the indices_container. Currently, all screen sizes display the index name, price, 1-day change, and year-to-date (YTD) change for each row. I only want to show the index name and YTD change on smaller screens.

My application is built using Flask and Bootstrap, so I'm unsure if achieving this without tools like React or Vue is possible. Can this be accomplished using @media queries or browser JavaScript?

Here's a snippet from the index.html file:

{% extends 'base.html' %}

{% block body %}
    {% with messages = get_flashed_messages() %}
      {% if messages %}
        {% for message in messages %}
          <div class="alert alert-warning alert-dismissible" role="alert">
          <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
            {{message}}
          </div>
        {% endfor %}
      {% endif %}
    {% endwith %}
<div class="indices-container">
  <div class="row">
    {% for index in total_payload.get('indexes').get('meta_data') %}
    <div class="col-sm-2 text-center">
      {% set d = total_payload.get('indexes').get(index) %}
      {{ "{} ${:.2f}".format(index, d['current_price']) }}
      {{ "{:0.2f}% 1-Day".format(d['percent_change']) }}
      {{ "{:0.2f}% YTD".format(d['ytd_percent_change']) }}
    </div>
    {% endfor %}
  </div>
</div>
<div class="sp500-table-container">
  <div class="table-responsive" id="sp500Table">
    <table class="table table-light table-striped table-sm" id="sp500Table">
      <thead class="thead-light">
        <tr> {% for col in total_payload.get('companies').get('meta_data') %}
          <th>{{ col }}</th>
          {% endfor %}
        </tr>
      </thead>
      <tbody> {% for num, r in enumerate(total_payload.get('companies').get('sp500companies')) %}
        <tr>
          <td>{{ num+1 }}</td>
          <td>{{ r.get('Symbol') }}</td>
          <td>{{ r.get('Security') }}</td>
          <td><a href="{{ r.get('sec_filings') }}" target="_blank">link</a></td>
          <td>{{ r.get('Sector') }}</td>
          <td>{{ r.get('SubSector') }}</td>
          <td>{{ r.get('Headquarters') }}</td>
          <td>{{ r.get('DateFirstAdded') }}</td>
        </tr> {% endfor %}
      </tbody>
    </table>
  </div>
</div>

<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p.name-price").css("color", "red");
  });
});
</script>
{% endblock %}

Snippet from the style.css file:

html {
    font-family: Arial, Helvetica, sans-serif;
}
body {
    /* padding-bottom: 80px; */
    /* height: 100% */
}
main {
    /* display: flex; */
    /* flex-direction: column; */
    /* flex-grow: 1; */
    padding-bottom: 80px;
    overflow: hidden;
}
footer {
    padding-top: 80px;
}
.indices-container {
    margin: auto;
}
.sp500-table-container {
    height: 70vh;
    width: 100vw;
    overflow: auto;
    position: relative;
    padding-bottom: 16px;
    margin: auto;
    /* flex: 1; */
    /* margin-bottom: 16px; */
}

Answer №1

You can achieve this using CSS Media Queries, without the need for any extra libraries.

Here's an example of how it could be implemented:

@media (max-width: 400px){
  .indicie-payment { display: none; }
  ...
}

However,

If you're already utilizing Bootstrap, you have the option to leverage the pre-existing utility classes for display provided by Bootstrap.

In your scenario, you would simply wrap certain elements in a container like div or span and apply a utility class such as d-sm-none

This approach would look something similar to the following:

<div class="indices-container">
  <div class="row">
    {% for index in total_payload.get('indexes').get('meta_data') %}
    <div class="col-sm-2 text-center">
      {% set d = total_payload.get('indexes').get(index) %}
      <span class="d-sm-none">{{ "{} ${:.2f}".format(index, d['current_price']) }}</span>
      <span class="d-sm-none">{{ "{:0.2f}% 1-Day".format(d['percent_change']) }}</span>
      {{ "{:0.2f}% YTD".format(d['ytd_percent_change']) }}
    </div>
    {% endfor %}
  </div>
</div>

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

Learn how to implement a split background effect by simply clicking the SPLIT button

let context = canvas.getContext("2d"); // for canvas size var window_width = window.innerWidth; var window_height = window.innerHeight; canvas.width = window_width; canvas.height = window_height; let hit_counter = 0; // object is created using class clas ...

Is it possible for Susy to output a pixel-based span?

As a newbie to Susy, I hope you don't mind if I ask a seemingly silly question... I'm trying to figure out how to calculate responsive padding within a Susy grid. The standard formula is: (target / context) x 100. Is there a way for Susy to pr ...

Invoking a static method within a cshtml document

I am currently working on implementing a clickable DIV within a vertical tab panel. My goal is to have a specific static method called when the DIV is clicked. Here is what I have done: <div class="tabbable tabs-left"> <ul class="nav nav-tabs"> ...

Utilizing jQuery taggd to add annotations to images

I am currently utilizing the taggd Plugin to develop an application that creates a tag whenever any part of the body is clicked. I have successfully implemented most aspects of it, but I am facing an issue with the coordinates. The tags are sometimes creat ...

Customizing ExtJS 4's CSS reset specifically for tailored HTML inside components

I am currently in the process of upgrading an existing application from Ext 3.x to 4. I have successfully enabled Ext's scoped reset CSS option to prevent Ext from applying its CSS reset to my entire application. However, I am now facing a new issue. ...

CSS trick that works on iOS16 as well

Previously, this CSS workaround was effective up to iOS version 15.6; however, it does not seem to be functioning in iOS 16. @media not all and (min-resolution:.001dpcm) { @supports (-webkit-appearance:none) {} } Are there any updated techniques avail ...

An error in PHP has been detected within the CodeIgniter framework

I have encountered an error that has been frustrating me lately: An unexpected PHP Error occurred with the following details: Severity: Warning Message: strip_tags() expects parameter 1 to be string, array given Filename: inscription/loginform3.php Line ...

Retrieve the website address from a string of HTML code

I'm struggling to extract the URL from a given String that contains an HTTP response with an HREF tag. I've managed to identify the start of the links, but I need to stop the string as soon as the HREF tag ends. How can I accomplish this? public ...

Can the outcomes be showcased again upon revisiting a page?

Whenever I navigate away from and return to my filter table/search page, the results vanish. I'm looking for a way to preserve the results without reloading the page. Essentially, I want the page to remain as it was originally, with the search results ...

Enhance your website's user experience with jQuery by implementing smooth scrolling alongside

I have a fixed header at the top of my page. When it scrolls, I want to ensure that it does not cover or hide any of my content, especially the top portion of the section. // This code enables smooth scrolling (source: css-tricks) $('a[href*="#"]:no ...

Backstretch malfunctioning

Looking to enhance my webpage with a backstretch image slideshow effect using the body background, but encountering issues. The code I have included before the </head> tag is: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery ...

determining the number of td elements in a row of a table located within an iframe

When I interact with a cell in a table within an iframe, I want to determine the number of cells in that row. If a cell is actually a span element, I would like to consider it as part of the cell count. The iframe may contain multiple tables without any s ...

Problem with Labels Overlapping and Blocking Text Fields

My issue is that when I interact with the text field, the label "Type your New Task here" moves up and gets covered by what looks like a white overlay. How can I fix this so that the label stays visible at all times? Prior to engagement: https://i.stack.i ...

Limiting the input in a text box to only allow whole numbers and no decimal values

What is the best way to limit a textbox to only accept whole numbers and exclude decimal values and alphabets? ...

What is the best way to clear and fill a div without causing it to resize?

I am faced with a challenge involving four thumbnail divs labeled .jobs within a #job-wrap container. When a .job is clicked, I want the #job-wrap to fade out, clear its contents, load information from the selected .job, and then fade back in. However, whe ...

Tips for moving a title sideways and adjusting the bottom section by x pixels

I am seeking to accomplish a design similar to this using CSS in order to create a title of <h1>DISCOVER <span>WEB 3</span> DIMENSIONS</h1>. How do you recommend achieving this? Thank you, I have searched on Google and asked frie ...

Using Javascript to dynamically add variables to a form submission process

Looking to enhance my javascript skills, I've created a script that locates an existing id and exchanges it with a form. Inside this form, I'm aiming to incorporate javascript variables into the submit url. Unsure if this is feasible or if I&apo ...

Storing the selected values from multiple checkboxes into an SQLite database with PHP PDO

Hi, I have two checkboxes named "Male" and "Female". If a person selects "Male" and does not select "Female", I want it to input nothing or false in the database. However, if "Female" is not selected, an error is returned: Undefined index: Female in /stora ...

Steps for splitting a numbered list and adding an image above each item:

I have a challenge I'm trying to tackle with my list: My goal is to create a long, numbered list that is divided into different sections I also want to include an image within each list item and have it display above the numbered title of the sectio ...

Unique version: "Each tab uses a unique pagination system that ultimately leads to the same content

Apologies for the novice question. Currently, I have: • a webpage with different tabs, each containing a pagination The issue arises when clicking on a page in one pagination, it redirects to: • a different tab For example, clicking on page 2 in t ...