I have a text (in a div) which shows on desktop and mobile screens.
Expected
I want the text to only show in @media only screen and (max-width: 768px)
How to
hide the div with
display:none
oris there any other solution?
I have a text (in a div) which shows on desktop and mobile screens.
Expected
I want the text to only show in @media only screen and (max-width: 768px)
How to
hide the div with display:none
or
is there any other solution?
Use media query.
Set display:none
to div and then apply display:block
for mobile using max-width media query.
Stack Snippet
div {
display: none;
}
@media only screen and (max-width: 768px) {
div {
display: block;
}
}
<div>Text</div>
or you can use the min-width media query. Less code here
Stack Snippet
@media only screen and (min-width: 768px) {
div {
display: none;
}
}
<div>Text</div>
It didn't work for me or i couldn't figure it out. so i used this..
CSS
.hideonphone{ display: none;}
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px){ .hideonphone{ display: inline;}}
HTML
<div class="hideonphone"> The text goes here</div>
Maybe is the same solution but i'm inexperienced.