Answer the question
In order to leave comments, you need to log in
Variable change based on screen width?
How can I change the value of a variable depending on the screen width?
I'm trying to do it like this:
@media (min-width: 767px) {
$size: 1vmax;
}
@media (max-width: 767px) {
$size: 1.5vmax;
}
h2 {
font-size: $size;
}
Answer the question
In order to leave comments, you need to log in
I was helped by assigning a CSS ID to the element and then I accessed the properties of the variable through Java Script:<div id="7888">
<script>
const mq = window.matchMedia('(max-width: 570px)');
if (mq.matches) {
// ширина окна меньше, чем 570px
document.getElementById("7888").style.height = "500px";
} else {
// ширина окна больше, чем 570px
document.getElementById("7888").style.height = "900px";
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question