I have this HTML:
<li><a href=""><i class="fa fa-iconname" style="vertical-align: middle;"></i>Link Name</a></li>
I am then using this media query in my CSS:
@media (max-width: 1000px) {
...
}
how can i change my tag to:
<i class="fa fa-iconname lg-2x" style="vertical-align: middle;"></i>
when the media query takes effect?
Media queries are commonly associated with CSS, but they can be used in HTML and JavaScript as well.
You don't. Instead, you define new rules that apply to the class which do the styling you want done. Media queries can't add or remove classes to elements, they merely change what rules apply to elements.
The @media rule is used in media queries to apply different styles for different media types/devices. Media queries can be used to check many things, such as: width and height of the viewport. width and height of the device.
Well... if you're using CSS custom properties (CSS variables) and wanted to reference them in a media query, you probably discovered that you can't use custom properties in this context. CSS custom properties weren't designed for that use case.
You can use pure css to achieve this by just replicating the list-item and toggle with media query like this:
HTML:
<li class="bigScreen"><a href=""><i class="fa fa-iconname"></i>Link Name</a></li>
<li class="smallScreen"><a href=""><i class="fa fa-iconname lg-2x"></i>Link Name</a></li>
CSS:
@media (max-width: 1000px) {
.bigScreen {
display:none;
}
.smallScreen {
display:block;
}
}
@media (min-width: 1001px) {
.bigScreen {
display:block;
}
.smallScreen {
display:none;
}
}
You can not do that with css, but you can with JavaScript or jQuery.
fa-2x is essentialy: font-size: 2em;
. So, you can do this:
@media (max-width: 1000px) {
.fa-iconname {
font-size: 2em;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With