best way to create a class/data-attribute to hide content on certain devices
Hey, what would be the best method to create a class/data-attribute to hide content on certain devices?
I'm using a data-attribute here. For the example codepen, i'm trying to hide a div with
display: flex;
on it whilst on a mobile viewport, whilst having it display otherwise. The problem is, since the data-attribute is using display: none
to hide the div once it gets to mobile, the display: flex;
overrides it and it doesn't disappear. I can't utilize !important
since if i put it on the display: none
, it makes the div disappear altogether, and if i put it on the display: flex;
it gives the same result as the initial problem.
Is there a more efficient way to do something like this so problems like this aren't encountered. Thanks in advance.
https://codepen.io/deerCabin/pen/oNOQQXm?editors=110021 Replies
use a media query
unless you wanna do it from javascript, in which case you should stop and use a media query
alrighty, media query it is, thanks guys.
is there no way to make it into a utility class at all though to prevent repeated code of hiding things haha?
you mean, like
.hide-desktop
?yeah exactly that
the same way you do with anything else?
yeah, but in my example codepen i showed an issue with doing it the normal sort of way
unless you mean put it in a media query like you said?
it's a slightly tiny bit more complicated than that, but not a lot
but yes, everything should be in media queries
@media (min-width: 50rem) {
<-- by the way, don't use rems on media queriesoh, hm, what would you suggest instead?
pixels
would you mind explaining please?
ah okay
you have to set the display value inside and outside the media query
would you mind showing an example please?
yes: check bootstrap
ohh bootstrap has it
thanks
you're welcome
so something along the lines of this?
does it work?
indeed it does
are you happy with it?
yeah it seems to be the most efficient way i can think of