In the following example, I want to display only one div
, depending on the device.
I'm familiar with how to use @media
to override a CSS class but not how to do a conditional.
<style type="text/css"> @media (max-width : 770px) { ... } @media (max-width : 320px) { ... } //do I need another for the desktop? </style> //if desktop <div style="width: 400px; float: left;"> this is desktop <a href="somepage.html"><img src="aLargeImage.png"/></a> </div> //if mobile <div style="width: 200px; float: left;"> this is mobile <a href="somepage.html">just text</a> </div>
Any suggestions?
Yes, CSS works on Android devices. In most cases, CSS can be used to style websites that are viewed on Android devices just like they would be on any other type of device.
If you want to style a native android app, there is no support for CSS. Instead android has it's own mechanism. The complete list of options is only available at the source code. You may use WebViews in your native Android app, to display HTML which is packaged with the app, then you can use CSS like in any HTML site.
Here's an example of how it can be done conditionally without javascript:
//CSS .visibledevice {display:none;} .visibledesktop {display:display;} @media (max-width : 320px) { .visibledevice {display:block;} .visibledesktop {display:none;} } //in the page <div class="visibledesktop">this displays for desktop and tablet</div> <div class="visibledevice">this displays for mobile</div>
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