I've been experimenting with my portfolio site (have a look at www.imkev.in
) and I'm facing some issues on the mobile version. Despite having media queries in my CSS that should trigger a switch to smaller file sizes and differently cropped images for screen widths below 530px, the background image elements don't seem to be cooperating. The layout of other page elements switches as intended at lower screen widths, which confirms that the basic media query is functioning properly.
Oddly enough, when I shrink the browser window size on my desktop to less than 530px, it correctly transitions to the alternate images. Furthermore, the mobile device emulators I've tested online (like Chrome developer tools) display the expected behavior. It seems like the issue only arises on real mobile devices.
Below is the CSS snippet I am using:
.portfolio-background {
background: url(/assets/images/background1-small.jpg) fixed;
background-size: cover;
@media (min-width: 530px) {
.portfolio-background {
background: url(/assets/images/background1.jpg) fixed;
background-size: 100% 100%;
}
}
I have attempted adjusting the background-size property to "cover" within the smaller media query, but it didn't resolve the problem. Additionally, I have set the viewport meta tag at the top of my HTML document to ensure the browser window width matches the device's width:
<meta name="viewport" content="width=device-width, initial-scale=1">
Do you have any suggestions?
EDIT: I am utilizing a compiler and the code I initially provided was before the compiler worked its magic. I have updated the post to include the actual code output. Still working on finding a solution.