Detect Tablet portrait/landscape

Hi guys,

i need to detect for a project if my tablet is in a portrait or landscape mode. Is it possible to detect this with the mobile detect plugin? Until now i didn’t found a solution yet.

Thanks for any help/advise!

What is your use-case? You can easily check it with CSS as well, if you would like to apply some styling based on the device orientation:

@media screen and (orientation: landscape) {
    /* do something when the device is in landscape mode */
1 Like

I use it to have my navbar centered on desktop and tablet landscape mode.

<div class="
  <?php if(!detect()->isMobile() || (detect()->isMobile() && detect()->isTablet())): ?>
  <?php endif ?>

  <?php if (detect()->isMobile()): ?>
  <?php endif ?>

@gerardkd I will try to use that instead :slight_smile: Thanks for the idea!

1 Like

Mobile detect does not support orientation of devices. If you need device detection, you can combine mobile detect with CSS media queries as suggested by @gerardkd

1 Like

Thanks it works now! was easier then i thought :grin:

Occasionally, you need this in javascript too - I use head.js for this. Its no longer maintained but still a very useful script. If that bothers you, there is an equivalent that works alongside Modernizr., but its not quite as powerful.