img
{
width:100%;
height:auto;
}
I am looking to adjust the height of an image based on the device screen size without the need for scrolling. For example, I want the image width to be 2000px and height to be 1500px.
img
{
width:100%;
height:auto;
}
I am looking to adjust the height of an image based on the device screen size without the need for scrolling. For example, I want the image width to be 2000px and height to be 1500px.
When dealing with CSS only, one approach is to utilize media queries with predetermined values for viewport widths. There are numerous resources available online detailing typical device widths that you can incorporate as needed. For instance:
img { height: 1500px; width: 2000px; }
@media (max-height:520px) {
img { width: 693px; height: 520px; }
}
@media (max-height:515px) {
img { width: 686px; height: 515px; }
}
@media (max-height:510px) {
img { width: 680px; height: 510px; }
}
@media (max-height:505px) {
img { width: 673px; height: 505px; }
}
@media (max-height:500px) {
img { width: 666px; height: 500px; }
}
/* ... and so forth ... */
This method proves effective when relying solely on CSS, albeit necessitating manual adjustment of device width thresholds.
If considering the use of Javascript or jQuery, image dimensions can be dynamically adjusted based on window size changes, including resizing events.
Below is a functional demonstration of JavaScript/jQuery code that modifies image dimensions in response to window size variations:
$(document).ready(function(){
window.onresize = function(event) {
if($(window).height() < $(window).width()){
// adjust based on device height
var $windowheight = $(window).height();
var $origheight = parseInt($('img').css('height'));
var $diff = $windowheight/$origheight;
var $origwidth = parseInt($('img').css('width'));
var $newwidth = $origwidth * $diff;
console.log("h: "+$windowheight+" w: "+$newwidth);
$('img').css('height',$windowheight);
$('img').css('width',$newwidth);
}else{
// adjust based on device width
var $windowwidth = $(window).width();
var $origwidth = parseInt($('img').css('width'));
var $diff = $windowwidth/$origwidth;
var $origheight = parseInt($('img').css('height'));
var $newheight = $origheight * $diff;
console.log("h: "+$newheight+" w: "+$windowwidth);
$('img').css('height',$newheight);
$('img').css('width',$windowwidth);
}
}
});
The example provided includes somewhat messy code due to its impromptu creation, but it effectively achieves the desired outcome. Certainly, room for improvement exists.
Can someone help me troubleshoot the issue with displaying/overflowing the .drop-down outside of the .item box in this demo? I need to keep the height of the .item as auto but for some reason, I can't enable overflow visible on it. .item{ backg ...
I'm having trouble with CSS animations on an HTML element, specifically when it comes to positioning the element freely on the page. How can I achieve this? I've attempted to use the following code snippet in order to position the HTML element a ...
I am currently working on adjusting the text size for both header and paragraph information in a listview. Below is the JQuery code that I have implemented: $('#rc1').prop('checked', 'true', function(){ $(".feedContainer ...
I would like to save all the input values from a form into separate divs as they are entered. For text input boxes, I have successfully implemented it using the following code: <input type="text" class="form-control" onkeyUp="document.getElementById(& ...
Is it possible to change the width of the image in this carousel? How can I resize the image without affecting the red box? I've tried numerous solutions on various forums, but none seem to work. The image just won't shrink the way I want it to ...
$(document).ready(function () { $('.mobile-nav-button').on('click', function() { $( ".mobile-nav-button .mobile-nav-button__line:nth-of-type(1)" ).toggleClass( "mobile-nav-button__line--1"); $( ".mobile-nav ...
Is there a way to trigger a click function using JQUERY on the div that includes the text "Save as JPEG"? The div with the ID "graph1" remains static while all other nested divs are dynamic. Please note that the dynamic div containing the text does not h ...
After creating a navigation bar with bootstrap, I wanted to make the active tab stand out above the others. Here's what I achieved: https://i.sstatic.net/lmPz8.png Once I managed to connect the tabs with the content using a "before" class, everythin ...
Exploring content and sidebar: .border { border: 1px solid black; } <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device- ...
Is there a way to keep the sort icon visible at all times in mudgrid without any default sorting using mudblazor? I have implemented the advanced data grid from the following link:- I have attempted using sortable=true on both the column and datagrid but ...
I am a beginner with the Parse database and I am currently working on implementing a code that allows users to sign up, with their information stored in the Parse database. However, I am encountering an issue where the values are not uploading as expected. ...
My attempt to center an image in the div didn't quite work out as planned. Here's the snippet of my html and css: .col-xs-4 { background-color: lightgrey; width: 300px; height: 200px; border: 6px solid green; padding: 25px; margin: ...
I've been struggling to troubleshoot an issue with a JavaScript accordion menu on my WordPress site. When I try to click the accordion button, it doesn't reveal the hidden content beneath it. I've attempted various solutions, but none have s ...
I'm struggling with creating nested divs similar to the layout shown in the linked image. Image Could someone please assist me in achieving this? .demo-container { padding: 30px; border: 1px solid #e2e4e7; background-color: #f5f ...
Currently, I am experimenting with adding jQuery to my Cargo Collective website: I have been working on a mouse-tracking jQuery effect that I really like, but I am facing an issue where the script does not stay contained in a specific section of the site. ...
Is it possible to modify the text color of "Contacte-nos" on hover? .popmake-contacte-nos { background-color: #fffff7; /* Green */ border: none; color: black; font-weight: bold; padding: 15px 32px; text-align: center; text-decoration: n ...
Struggling to articulate this, so here is a little jsfiddle demo: http://jsfiddle.net/UwEe2/ The concept I am aiming for is very similar to the one in the demo, however, I require the image to be perfectly centered. In other words, I need the center of t ...
Does anyone know of a plugin or method that can achieve this? I have a website at this link, and at the bottom there is a map. I'm looking to add a small overlay box on top of the map with contact information inside. Edit: The box should be position ...
<!doctype html> </html> <head> <title> </title> <link href="../assets/css/bootstrap.css" rel="stylesheet"> <link href="sigin-style.css" rel="stylesheet"> &l ...
In my current project, the user is able to input a city and the background of the page changes to display an image of that specific city. This image is obtained through an API call to Pixabay API, with the result stored in a variable named "background". Ho ...