Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:39:03+00:00 2026-05-31T21:39:03+00:00

I need to dynamically load banner images into a HTML5 app and would like

  • 0

I need to dynamically load banner images into a HTML5 app and would like a couple of different versions to suit the screen widths. I can’t correctly determine the phone’s screen width, so the only way I can think of doing this is to add background images of a div and use @media to determine the screen width and display the correct image.

For example:

 <span style="background-image:particular_ad.png; @media (max-width:300px){background-image:particular_ad_small.png;}"></span>

Is this possible, or does anyone have any other suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:39:05+00:00Added an answer on May 31, 2026 at 9:39 pm

    @media at-rules and media queries cannot exist in inline style attributes as they can only contain property: value declarations. As the spec puts it:

    The value of the style attribute must match the syntax of the contents of a CSS declaration block

    The only way to apply styles to one specific element only in certain media is with a separate rule in your stylesheet (be it linked externally or internally in a <style> element), which means you’ll need to come up with a selector for it. You can grab one using your browser’s dev tools, or figure out a class and/or ID combination that isolates this element:

    #myelement { background-image: url(particular_ad.png); }
    
    @media (max-width: 300px) {
        #myelement { background-image: url(particular_ad_small.png); }
    }
    

    If you’re unable to find a selector that will reliably match this element alone due to the nature of your page, you can use a custom property, provided you don’t need to worry about specificity or Internet Explorer:

    :root { --particular-ad: url(particular_ad.png); }
    
    @media (max-width: 300px) {
        :root { --particular-ad: url(particular_ad_small.png); }
    }
    
    <span style="background-image: var(--particular-ad);"></span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to dynamically load and put on screen huge number of images —
I need to dynamically load content from HTML emails into some type of content
I need to dynamically load a CSS stylesheet into a page that's on a
I need to dynamically load many (sometimes hundreds) of thumbnail images. For performance reasons
Question Updated for Bounty In Flash I need to load a dynamically generated XML
What's the Zepto equivalent of jQuery.getScript()? I need to dynamically load a JavaScript file
For an application I am writing, I have the need to dynamically load content
I need to dynamically load several JavaScript file assets in a very specific order
I have instances where I need to dynamically load 5-10 literals with the same
I am trying to dynamically load a KML file into a map depending on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.