Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCSS media query aspect ratio not working

im new to SCSS and im trying to maintain good quality of cover image of my site. Anyways, the css is working good, meanwhile the scss is not.

SCSS

#page-login-index {
@media screen and (min-aspect-ratio: 5/4) {
    background-color: red;
}}

CSS

@media screen and (min-aspect-ratio: 5/4) {
#page-login-index {
background-color: red;
}}

I need to do that in SCSS, since im loading some things from PHP. I've noticed that aspect-ratio and device-aspect-ratio is not working while min-height is working fine.

like image 653
Jotosha Avatar asked May 22 '18 10:05

Jotosha


People also ask

What is aspect ratio in media query?

4.6. The ' aspect-ratio ' media feature is defined as the ratio of the value of the ' width ' media feature to the value of the ' height ' media feature.

How do you set a media query for a range of width?

Setting a particular "width-range" isn't any different from the way media queries are created. The only difference is the addition of more media feature expressions (that is, the screen width sizes). Take a look: @media only screen and (min-width: 360px) and (max-width: 768px) { // do something in this width range. }

Why is media query not working?

Media Query Not Working on Mobile Devices If media queries work on desktop and not on mobile devices, then you most likely haven't set the viewport and default zoom. Note: You only need to add one of the code lines above, and usually, the first one does the job.

How do you add min width and maximum width in media query?

If you want to include both min and max width for responsiveness in the browser, then you can use the following: @media (min-width: 768px) and (max-width: 992px){...} @media (min-width: 480px) and (max-width: 767px) {...}


1 Answers

I figured it out.

when i wrote

    @media (min-aspect-ratio: 5/4) {
        background-image: url('someurl');
    }

scss compiled it to (min-aspect-ratio: 1.25) which was wrong

i had to put it as a string into variable like: $aspect54 : "(min-aspect-ratio: 5/4)";

so in the end it looked like this

$aspect54 : "(min-aspect-ratio: 5/4)";        
@media #{$aspect54} {
            background-image: url('someurl');
        }
like image 78
Jotosha Avatar answered Sep 28 '22 15:09

Jotosha