What is the best way to adjust the image on mobile portrait view to ensure it fits properly without distorting the aspect

I am facing a perplexing issue with my code. It seems that simply using height: auto; is causing the image to disappear, so I have resorted to manually setting the height to a specific number like 700px. You can refer to this JSFiddle for more details.

Is there a way to maintain the width and height of the image in portrait view on mobile devices?

Here is the HTML code:

<div style="background-image: url(&quot;https://mario.nintendo.com/static/fd723b2893d4d2b39ef71bfdb4e3329c/579b4/mario-background.png&quot;);" class="cpi-wall-detailed-image"></div>

And here is the CSS code:

.cpi-wall-detailed-image {
    width: 100%;
    height: 768px;
}

Answer №1

Here is a suggested code snippet for you to try:

.cpi-wall-detailed-image {
  width: 100%;
  height: 768px;
}

@media only screen and (max-width: 600px) {
  .cpi-wall-detailed-image {
  zoom:0.5
}
}
@media only screen and (max-width: 475px) {
  .cpi-wall-detailed-image {
  zoom:0.4
}
}

Answer №2

give this a try:

.cpi-wall-detailed-image {
  width: 100%;
  height: 2316px;
}

@media only screen and (max-width: 600px) {
  .cpi-wall-detailed-image {
  zoom:0.37
}
}
@media only screen and (max-width: 475px) {
  .cpi-wall-detailed-image {
  zoom:0.325
}
}

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

Is there a way to retrieve the modal's viewport height in Angular?

Is it possible to determine the viewport height of my ng bootstrap modal within my Angular application? Here is what I currently have: I have a modal with CSS styling as shown below: .modal-xxl { width: 95% !important; max-height: 90% !important; ...

Ways to specify distinct css styles according to varying number of elements

I need the Button element to always take up 100% of the container, no matter how many elements are inside. Check out my Fiddle link here: Js Fiddle Link <div class="inputFieldBoolean buttonSeries" data-type="Boolean"><button class="true" data-va ...

How can the input value be transmitted along with the formArray values?

I am currently working with a FormArray in my project where I can add new fields and submit the entire form data on button click. However, I am facing an issue trying to display and send an input field that is connected to the 'name' attribute wi ...

Rearrange the order of divs dynamically to prevent wrapping/overflow, no need for media queries

Can someone help me with this issue? I am trying to create a navigation bar with centered menus/links, a logo on the left, and call-to-action buttons and icons on the right. If the content overflows or wraps, I want the center column to move to the next l ...

Customize the style attribute in Bootstrap 4 using Popper.js

I've been attempting to adjust the position of a dropdown element, but I'm struggling to make it work. Utilizing Bootstrap 4 with Popper.js, I simply added a default dropdown without any custom styles to my page. However, it automatically applies ...

Adjustable value range slider in HTML5 with ng-repeat directive in AngularJs

I am facing a problem with my HTML5 range slider. After setting a value (status) and sending it to the database, when I reload the page the slider's value is always set to '50'. The slider is being generated within an ng-repeat from AngularJ ...

I must design a unique layout for my website

I am creating a webpage with various shapes and elements. However, I am facing a challenge with creating a shape that is commonly used. In platforms like Khan Academy, there is simulated programming where shapes can be easily created with a simple command ...

Ways to modify styles defined in the global style.scss file using a child component's CSS and constraining it to affect only that specific component

When working on my Angular project, I have implemented some CSS styling in the global style.css file located at src/style.css. However, there are instances where I need to modify certain styles within a specific component only. Currently, I am able to achi ...

Top choice for mobile app error reporting and logging

Exciting news - our mobile android app is now ready for our testers to download on their personal phones! However, we are facing a challenge with constant crashes that we can't seem to fix. Since the app is no longer running in our local android stud ...

Trouble with CSS submenus: Are your lists not appearing as they should? Potential style override

I am encountering an issue with my dropdown mega menu. I have two sets of list items that should be displayed vertically side by side with bullet points in the dropdown, but only one list is appearing despite coding for both. Additionally, the list elemen ...

The issue arises when radio buttons allow for multiple selections and labels cannot be displayed in a single row

I am facing an issue with the radio buttons displayed in the Bootstrap format. The labels for the radio buttons are not aligning on the same line as the buttons. Below is the code I am using: <div class="row"> <div class="col-lg-4&q ...

issues arising from a growing css division

I am facing an issue where the tiles on my webpage expand on hover, but some of them are partially covered by neighboring tiles. How can I resolve this problem? Here is the CSS code snippet: .tile { position: absolute; width: 86px; background-color ...

"What is the best way to programmatically set all options as selected in an HTML select element using JavaScript

There are two select tags in HTML. The first one includes all the countries in the world, while the second only contains the countries that the user has selected. <form action="/fixsongs.fix"> <table> <tr> < ...

Issue with AngularJs NgRoute

Encountering an issue with ngRoute on angularjs, version 1.6.9. Developed a simple route like "/test/:yourname" where "yourname" serves as a variable, however facing the following challenges: 1) Visiting the address "http://localhost:8080/test/rafael" re ...

Focused input filter in a tabular header style

I've been working on customizing the Tabulator header filter to have a more "flattened" style, as requested by my boss. In my CSS, I added the code ...input:focus{border:1px solid #1bb394} to change the input border to 1px green. While this change tak ...

The loading of the Bootstrap tagsinput has encountered an error

I am facing an issue with my Django application where tags are not loading properly in an input field using jquery. It seems like the application is unable to locate the bootstrap-tagsinput.css and bootstrap-tagsinput.js files. Can anyone provide guidance ...

What is the best way to gather Data URI content through dropzone.js?

I am currently utilizing Dropzone for its thumbnail generation feature and user interface. However, I am only interested in using the thumbnail generation ability and UI and would prefer to collect all the data URIs myself and send them to the server via a ...

Conceal a section of a container with the click of a button within a WordPress Plugin

I am currently utilizing a Wordpress plugin known as contact form 7 to construct an email list for an upcoming website project. The client has specifically requested that we avoid using services like mailchimp due to their preference of not sending ANY ema ...

Tips for positioning "THANK YOU" in the center

and this is a snippet of my coding <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class=" ...

Create a dynamic JavaScript animation with frames

Is there a simpler method to animate a sprite with just 4 frames in HTML Canvas? Having a background in AS3 and C#, I found the code below to be overly complicated. It seems like I'll be spending hours trying to decipher it. Is there a more modern or ...