Struggling to make the image adapt to mobile screen sizes, even after applying a width of 100% and

After spending countless hours researching online, I still can't figure out how to make the image responsive on mobile devices. On a computer screen, it looks fine:

https://i.sstatic.net/sCPbA.png

However, when I inspect the element and view the images, they appear squished like this:

https://i.sstatic.net/TexpL.png

The images are being resized with reduced width, which is not what I want.

I've tried using media queries to adjust the width and height, but it's not working as expected.

Here is an example of my HTML code:

<div id = "projects">
        <div id = "we-cycle">
            <img id = "we-cycle-image" src = "./photos/we-cycle.png" width = "100%" height = "auto">
        </div>

And here is the relevant CSS code:

#projects {
    width: 80%;
    margin: 300px auto;
    margin-left: -30px;
    padding: 20px;
}

#we-cycle-image {
    position: relative;
    max-width: 80%;
    height: auto;
}

@media screen and (max-width: 500px) {
  #we-cycle-image {
    width: 100%;
    height: auto;
  }
}

Answer №1

Indeed, the issue with the images being distorted is due to their square aspect ratio not fitting properly on small screens. To resolve this, you can adjust the flex display by adding the style flex-wrap: wrap; to ensure the images wrap correctly.

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

CSS z-index property not functioning properly for Flowplayer on Firefox browser

I am attempting to create a layered div using z-index, with one of the layers containing a flowplayer. Once the layer is properly created, I plan to update the div's z-index value based on the logic of the program. The following code functions correct ...

Enhancing code with new Javascript functionality

Currently utilizing the WordPress Contact Form 7 plugin and in need of updating my existing JavaScript code to include an onclick function and data-img attribute for checkboxes. Due to the limitations of Contact Form 7 shortcode, adding attributes beyond i ...

What causes the vuetify tag not to render as HTML in the browser?

I ran into a styling issue while using Vuetify in my Nuxt 2 project. Upon inspecting the element in dev tools, I noticed that some Vuetify tags were not being converted to HTML as expected (they were displayed as div class="tag_name"). These unco ...

Implementing the rotation of an element using 'Transform: rotate' upon loading a webpage with the help of Jquery, Javascript, and

A div element designed to showcase a speedometer; <div class="outer"> <div class="needle" ></div> </div> The speedometer animates smoothly on hover; .outer:hover .needle { transform: rotate(313deg); transform-origin: ce ...

Changing CSS attributes with jQuery when conditions are met

After creating menus with expandable items that change style upon clicking, I encountered an issue where the styling changes were not being applied correctly. To address this problem, I followed Sushanth's suggestion and replaced $this with $(this), ...

Issue with responsive canvas height in Particle-JS

Recently, I've been working on a Bootstrap portfolio where I am experimenting with implementing particle.js over a profile picture. I placed the particles inside a DIV and set a background image as the profile photo. The issue arises when I reload th ...

How can we pass on the width from an image to its parent or grandparent element using CSS?

Creating a cohesive image gallery with captioned images of different aspect ratios is my goal. To maintain consistency, I desire the browser to display each image at the same height while preserving its original aspect ratio by adjusting the width accordin ...

Is there a way to attach a CSS class to a BoundField in order to locate it using jQuery?

I need to assign a specific class name to certain BoundFields within the GridView control. This way, after the GridView has been populated with data and displayed, I would like to have something similar to the following: <td class="Tag1">Some data c ...

Applying a dynamic translate3d transformation on the ::after element using CSS3

My current challenge involves manipulating a pseudo ::after element using translate3d If I hardcode the values, it's straightforward: div::after { ... transform: translate3d(40px, 40px, 0); } Now, I want to dynamically set the value for the ...

Is there a way to clear out all items from the cart using PHP?

I have a shopping cart with items that I want to remove all at once. I tried creating a submit button with the post method called 'remove_all', but it's not working and showing an error message saying "The requested URL was not found on this ...

Discover the precise number of columns and rows that make up a circle

Is there a way to display a popup message when clicking on a circle in the array to see the number of rows and columns that circle is from the starting point (1,1)? I'm looking for assistance with implementing this feature. var c = document.getEleme ...

using javascript to change a link's state with a click action

I have a question that is related to the topic discussed here: Making a link stay active displaying hover effect upon click using javascript. I am looking for a way to disable the active class when the same link is clicked again. Any assistance on this mat ...

The value entered in the HTML input is not being recognized by PHP

I'm facing an issue with my project (index.php), which is a HTML webpage. I am trying to use the 'include' function to bring in the header and footer (header.php, footer.php). Additionally, I want the current date to automatically populate i ...

What's the best way to use the keyboard's enter key to mark my to-do list

I'm looking to update my todo list functionality so that pressing enter adds a new todo item, instead of having to click the button. <h1 style="text-align:center">Todo List</h1> <div class="container"> ...

What is the best way to add a gradient color to the bottom of your content?

Seeking assistance in replicating the unique UI design featured in the image below, taken from a course description section on udemy.com. The goal is to create a gradient effect on specific parts of the content, similar to what is shown in the image. http ...

Uncovering the hidden gems within a data attribute

Trying my best to explain this clearly. What I have is a data-attribute that holds a large amount of data. In this case, I need to extract each individual basket product ID and display them as separate strings. The challenging part for me is locating thi ...

Verification symbols in Unicode

I'm on the hunt for a universal checkmark symbol that is compatible across various operating systems and web browsers. I've tested out the following two options: Version 1: ✓ Version 2: ✔ (source) However, these symbols seem to be working ...

AngularJS fails to prioritize the following element

Here is my HTML code: <div ng-app="app"> <form> <div class="form-group"> <label >Username</label> <input focus type="text" class="form-control" id="loginUserName" ng-model="userForm.crn" required/> ...

Pass information from a JavaScript script to the existing PHP file

I currently have a PHP file named content.php that is being displayed in the browser: <html> <head> <title>Content</title> <script src="content.js"></script> </head> <body> ...

Preventing numerous votes

Seeking advice on enhancing my voting system that permits users to upvote and downvote items. The main issue I am facing is with users casting multiple votes. Below is the current code implementation: <h4> Votes </h4> <table> <tr> ...