Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can CSS code redundancy with multiple media queries be avoided?

I have a picture with a specific size:

.image-size {
    height: 400px
}

For smaller screens, I decrease this size:

@media (max-width: 991px) {
    .image-size {
        height: 280px
    }
}

But when the page is printed, I need the original size:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@media print {
    .image-size {
        height: 400px
    }
}

I tried to avoid the code redundancy with

@media print, (max-width: 50000px)
    .image-size {
        height: 400px
}

@media (max-width: 991px) {
    .image-size {
        height: 280px
    }
}

but that did not work with small screens because the print size 400 was overwritten with the small screen size 280.

Is there a way to avoid the code redundancy?

Many thanks!

>Solution :

You can specify the media screen for responsive rules:


.image-size {
   height: 400px
}

@media screen and (max-width: 991px) {
    .image-size {
        height: 280px
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading