I am trying to create different displays for a webpage for desktop and mobile devices. Based on tutorials I have tried copying the following code right below the header section and before the body section.
<style media="all">
.mobile-display{display:none}
.desktop-display{display:block}
@media (max-width:800px){
.desktop-display {display:none}
.mobile-display {display:block}
}
</style>
<div class="mobile-display">
My mobile content.
</div>
<div class="desktop-display">
My desktop content.
</div>
This is located above all the content so that the content would be the same for types of devices and only the message at the top would be different. I expected to see the message "My desktop content" right above the webpage when viewing in the desktop and "My mobile content" above the webpage when viewing in mobile. Instead I saw "My desktop content" in both the desktop and the mobile versions. I would like help figuring out why it is not displaying correctly on mobile devices.
Note that I think that this is the only code relevant to the problem, but if needed I can include other code from the test page.
3
Answers
I am not sure if this is the best answer, but I found a way to get it to work. I found you can do it with php like this.
To use @media you have to follow rule.
For example,
I hope this answer can help you.
Good luck.
The CSS code you’ve provided seems correct for creating different displays for desktop and mobile devices using CSS media queries. Can you please confirm, that you have added a tag for responsive design.
Please add the following meta tag to your HTML , if you haven’t.
The tag with the name="viewport" and its associated content attribute controls the behaviour of a web page’s viewport on mobile devices. It is an essential part of creating responsive and mobile-friendly web designs.
If you have added the above tag and are still having issue then it can be other reasons, like,
If everything mentioned above is in order on your end and you are still experiencing issues, please share more of the code or a screenshot of your problem.