Adapting image loading based on screen size using media queries

I'm having trouble loading images for different screen sizes using only media queries. The image loads in the browser but doesn't display within the div container. I can't figure out what I'm doing wrong.

Here's the code:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
    <title></title>
    <link href="css/test.css" rel="stylesheet">
</head>
<body>
<pre>
    <script src="Jarts.js"></script>

</pre>
<div id="skjd2344jd"></div>

</body>
</html>

Here's the CSS:

 #skjd2344jd{
    height: 100%;
    width:100%;
}

@media only screen and (min-device-width: 480px){
#skjd2344jd {
   background-image: url("../img/optimal_small.png");
   background-repeat: no-repeat;
     }
}
@media only screen and (min-width: 481px) and (max-width: 1600px) {
#skjd2344jd {
   background-image: url("../img/optimal.png");
   background-repeat: no-repeat;
     }
}

Answer №1

The unique identifier will expand to cover the entire width and height of the body, assuming you have specified dimensions for your body element. Be sure to include a height value for your body and remember to include background-size:cover in your CSS for optimal display. Check out how your code can appear like here.

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

Generating PDF files from HTML code

To convert an HTML file to a PDF, I use The process involves using the following code: <script type="text/javascript" src="http://www.pdfmyform.com/js/pdfmyform.js"></script> <a onclick="pdfmyform(this);" href="#">PDF this page!</a& ...

Tips for inverting the z-index order of stacked divs

On my webpage, I have set up multiple columns enclosed in divs like this: <div class="first column" style="width:33%; float: left;"></div> <div class="column" style="width:33%; float: left;"></div> <div class="last column" style ...

What could be the reason for the failure of importing components on a local server?

Recently, I encountered an issue with the following code snippet: <head> <script src="bower_components/platform/platform.js"></script> <link rel="import" href="bower_components/voice-elements/dist/voice-player.html"> &l ...

Step-by-step guide on achieving 100% height for the <main> element in a Material UI drawer demo

I have a question regarding the Material UI drawer. In my project, I am trying to change the background color of the main tag. However, the main tag's height is restricted to the content inside. Check out this link for reference Setting the height t ...

Using Vuejs v-for on inline elements can remove unnecessary whitespace

While iterating through an array (or object) with v-for on an inline element in VueJS, there is no whitespace rendered around the element. Consider the following example: <div id="app"> Vue Rendering<br> <a v-for="fruit in fruits" ...

Incorporate a captivating background image into your SVG design

Currently working with Snap.svg, my aim is to include a background image on a polygon shape. The specific polygon in question is outlined as follows: <svg id="test" height="600" width="600" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= ...

What is the best way to use a HTML link to toggle the visibility of a <p> element using

I've been trying to figure out how to make a link show and hide a paragraph below it for some time now. I want to do this using just CSS. The paragraph should be hidden by default, then display when the link is clicked, and hide again with another cl ...

What is the best way to ensure a table is responsive while maintaining a fixed header? This would involve the table scrolling when it reaches the maximum viewpoint, while also keeping

Can anyone help me create a responsive table with a fixed header that scrolls when it reaches the maximum viewpoint without scrolling the entire page? I've tried using box-sizing: border-box; and overflow-x:scroll; but it didn't work. Any suggest ...

Is it possible to dynamically change the color of a box shadow using an event handler?

I'm currently in the process of developing an application that consists of six distinct topics organized within a flexbox structure, complete with a box-shadow effect. My objective is to dynamically alter the color of the box-shadow through an event ...

Issue encountered while submitting form on JQuery Mobile framework

Currently, I am in the process of developing a small web application utilizing JQuery Mobile and Multi Page architecture. The issue arises on my form as the second page. Upon clicking the submit button, an error message is displayed on my console (error i ...

Mastering the ngIf Directive in Angular: A Comprehensive Guide

Before you approve and publish, please take note: You are about to give your approval for the Industry Formile Deliverable. The content will be rendered when the specified condition is met. div class="form-group" ...

Insert HTML code into a specified location using a WordPress Plugin

How can I add a custom text to my WordPress website using a plugin in an HTML theme, and display it between the post and comments section? Is there a universal method for achieving this, regardless of the installed theme, so that I can effectively showcas ...

Applying the variables as elements within a foreach iteration

I'm currently developing a learning management system and encountering an issue with my code. foreach($datas as $data){ ?> <div style="background-color: #3B4FDF; border-radius: 3%; width: 30%; height: 220px; margin-right: 5%; cursor: poi ...

The Bootstrap Hugo Documentation website is experiencing difficulties and displaying the error message "failure to render 'page'"

Currently, I have bootstraps' source code downloaded on my Mac along with all the necessary node packages installed. Upon attempting to run hugo --cleanDestinationDir --printUnusedTemplates (hugo is properly installed), I encountered the following err ...

IMAGE CARDS WITH BOOTSTRAP 5

I created a bootstrap card with an image on the right side, but it doesn't fill the entire space. Below is the image of my bootstrap card: https://i.sstatic.net/k7xuT.png This is the code for my card: {% for book in thesis_details %} ...

Guidelines for launching a PHP/form results page in a new tab?

My current setup includes a form: <form action="bar.php"> <input type="hidden" name="foo" value="<?php SOME_STUFF(); ?>" /> <input type="submit" /> </form> This form is linked to a PHP script that takes the user input an ...

Is there a way to use jQuery to eliminate divs that contain multiple identical data values?

Is there a way to accomplish this? <div class="chat_timestamp_group" data-date="08-March-2016"></div> <div class="chat_timestamp_group" data-date="08-March-2016"></div> <div class="chat_timestamp_group" data-date="14-March-2016" ...

The jQuery toggle functionality seems to be malfunctioning when used alongside various other JavaScript code in close proximity

I am currently experimenting with a basic jQuery toggle button that I found while browsing through an example at How can I dynamically create derived classes from a base class: <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery ...

How to display a variable within a button group to impact a dropdown selection in Angular.js and HTML

Here is where I am at with my current project: <div class="container" ng-app="app" ng-controller="dataCtrl"> <h2>Test</h2> <h4>Choose a Category</h4> <ul class="nav nav-pills"> <li ng-repeat="cat ...

Utilizing Javascript to Trigger a Website Call Upon Changing a Select Box in HTML

Hello, I have a question. In my HTML code, I have a selection box. What I would like to achieve is that when the selection is changed, a website is automatically called with the selected value. For instance: <select> <option value="a">a&l ...