In my view, it is generally more efficient to establish the basic css rules required for your class and then adjust them for different screen sizes such as mobile, tablet, and larger desktops.
The issue you may be encountering could be due to another css rule overriding the one for the mobile version. Try removing the !important
from the desktop version's .single-product
if applicable.
By doing this, the problem should be resolved.
/* Desktop Version */
.single-product .woocommerce .has-product-nav span.onsale {
top: 7rem;
margin-top: 0px;
}
// Define styles for portrait orientation on mobile
@media screen and (max-width: 767px) and (orientation:portrait) {
.single-product .woocommerce .has-product-nav span.onsale {
top: 5rem !important;
}
}
// Adjust styles for landscape orientation on mobile
@media screen and (max-width: 767px) and (orientation:landscape) {
.single-product .woocommerce .has-product-nav span.onsale {
top: 4rem !important;
}
}