Can you use if-then in CSS/HTML? Here’s an example code
<style>
p {
font-size: 20px;
}
@media (max-height: 800px) {
p {
font-size: 10px;
}
}
</style>
I am someone who has a background in Python, so when I see that media query uses conditional statement I immediately think somekind of If-Then function, can you use an if-then conditional statement in CSS/HTML? Or does it have to be in a format where the “if” is replaced with “@media”?
No, Vanilla HTML OR CSS do not allow that, but the problem can easily by solved by the other member of the Web Dev Holy Trinity, Javascript.
And there are no overhead expenses, most browsers support Javascript today natively,