-
AuthorPosts
-
April 13, 2016 at 12:23 am #612245
Hello. Does anyone know how to prompt users to rotate their ipad screen from portrait to landscape with a message? I’ve found this clip that works well:
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { body { -webkit-transform: rotate(90deg); width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0; } }
However I’d like to somehow include a message with a .5 opacity black background asking the user to rotate the screen. Any suggestions?
April 13, 2016 at 1:33 am #612268Hey!
You could add a custom message that only appears on portrait, add this at the very end of your theme / child theme functions.php file:
add_action('wp_footer', function() { ?> <div class='rotate-message'>Rotate</div> <?php });
And Quick CSS:
.rotate-message{ display: none; } @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { .rotate-message{ display: block; } }
Cheers!
JosueApril 13, 2016 at 2:25 am #612302Hi Josue! Thanks for this! It looks like it’s exactly what I need. However, the code doesn’t seem to be registering. I tried placing the css in the child theme’s css instead of the quick CSS area but that didn’t seem to work either. Any thoughts?
April 13, 2016 at 2:41 am #612307Hi,
Can you post the link to your website please?
Regards,
JosueApril 13, 2016 at 2:43 am #612309Sure! Note that you’ll need to re-enter the snippet because I took it out.
April 13, 2016 at 3:01 am #612315Ok hand me an admin account via private reply too please.
Regards,
JosueApril 13, 2016 at 3:35 am #612323I’ve added the
add_action('wp_footer', function() { ?> <div class='rotate-message'>Rotate</div> <?php });
back into the child theme’s functions.php so you won’t need to enter that area. Thanks!
April 13, 2016 at 3:38 am #612326Hi!
Change the CSS code to:
.ipadportrait { display: none; } @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { .ipadportrait { display: block; } }
Best regards,
JosueApril 13, 2016 at 4:41 am #612377Hello. It looks like that didn’t work either. I see that the class you provided in the css above differs from that of the class in the functions.php snippet, why is this?
April 13, 2016 at 4:54 am #612386Hey!
We are working on your ticket please wait while we update the results here soon.Create a color section and hide the color section by default.
#colorsection { display:none; }
Use media queries to show it only in portrait mode on iPad
/* Portrait */ @media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation: portrait) { /* Your custom CSS to show content */ #colorsection { display:block!important; } }
for more info please check https://css-tricks.com/snippets/css/media-queries-for-standard-devices/
Cheers!
Vinay- This reply was modified 8 years, 8 months ago by Vinay.
April 13, 2016 at 7:56 am #612474How do I go about hiding the rest of the site in ipad portrait? Can I use
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { body { display: none !important;}}
and then somehow make the #colorsection an exception?
April 15, 2016 at 7:49 am #614603Hi!
The color section is inside the body tag so you can’t do that. This may work:
@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { body * { display: none !important;} #colorsection { display: block !important; } }
Don’t forget to change “#colorsection” to the actual color section selector or id. Note that this will hide all sections including the header, footer, etc.
Regards,
IsmaelApril 15, 2016 at 7:40 pm #615094Hi Ismael! It looks like this code hides the color section as well. Is there some way to make #colorsection { display: block !important; } of higher importance than the body * { display: none !important;} ?
April 15, 2016 at 9:08 pm #615144Hi!
Just like media queries for tablets and desktops we can target landscape and portrait mode in css.
1. Create 2 color sections on a page with 100% height and different background colors.
2. Add a custom ID to the 1st color section “#only-in-portrait” and some sample text like “Please Rotate Your Device”
3. Paste the below css in Quick CSS
#only-in-portrait { display:none; } /*Only in Portrait */ @media only screen and (orientation: portrait) { #only-in-portrait { display:block!important; pointer-events:none; } body{ overflow: hidden; } }
Like Ismale mentioned above you can combine this with device screen width to specify only in tablet portrait mode or mobile portrait mode.
You can add the rest of the page content below the 1st color section.Best regards,
Vinay- This reply was modified 8 years, 8 months ago by Vinay.
April 16, 2016 at 2:02 am #615229Hi Vinay,
The code that you provided makes it so that you can see the #colorsection only in ipad portrait, but you can also see the body and header as well. In order to hide the rest of the page i’d need to create a separate media query to display none in ipad portrait, and that would be a pain to add that class to each element on every single page of my site.
I would like to use the code that Ismael provided above but the only problem with it is that it does not display the #colorsection due to the following line that hides the rest of the site: body * { display: none !important;}
If there is a way that I can have this line: #colorsection { display: block !important; } take priority over the one above so that it shows on ipad portrait that would be ideal. If this is not possible then that’s okay, i’ll find a workaround. Hopefully this makes sense. Thanks!
April 17, 2016 at 8:01 am #615733 -
AuthorPosts
- You must be logged in to reply to this topic.