Target Mobile Landscape viewport #2397
Replies: 7 comments 3 replies
-
I think you'll want to look into Media Queries' Orientation. And then check out Custom Media Queries in Tailwind, which, ironically, is showing one how to target portrait orientation. |
Beta Was this translation helpful? Give feedback.
-
Thanks @Natetronn, I will check them out 👍 |
Beta Was this translation helpful? Give feedback.
-
Following said instructions, I created these custom screen sizes for You can double down on the media/breakpoints using stacked prefixes, eg: edit: as I have commented, landscape/portrait will trigger on a desktop display if the browser window is resized to be taller than it is wide (or the opposite). I have added two extra breakpoints to my original post, "tallOrWideAndLandscape" and "tallOrWideAndPortrait". You could reasonably rename this "mobileLandscape" and "mobilePortrait". module.exports = {
theme: {
extend: {
screens: {
'tall': {
'raw': `only screen and (max-height: 960px) and (max-width: 480px)`
},
'wide': {
'raw': `only screen and (max-height: 480px) and (max-width: 960px)`
},
'portrait': {
'raw': '(orientation: portrait)'
},
'landscape': {
'raw': '(orientation: landscape)'
},
'tallOrWideAndPortrait': {
'raw': `only screen and ((max-height: 960px) and (max-width: 480px) or (max-height: 480px) and (max-width: 960px)) and (orientation: portrait)`
},
'tallOrWideAndLandscape': {
'raw': `only screen and ((max-height: 960px) and (max-width: 480px) or (max-height: 480px) and (max-width: 960px)) and (orientation: landscape)`
},
}}}}; And tested them with this: <div class="invisible badge badge-primary xl:visible">XL</div>
<div class="invisible badge badge-primary 2xl:visible">2XL</div>
<div class="invisible badge badge-primary md:visible">MD</div>
<div class="invisible badge badge-primary sm:visible">SM</div>
<div class="invisible badge badge-primary lg:visible">LG</div>
<div class="invisible badge badge-primary tall:visible">TALL</div>
<div class="invisible badge badge-primary wide:visible">WIDE</div>
<div class="invisible badge badge-primary portrait:visible">PORTRAIT</div>
<div class="invisible badge badge-primary landscape:visible">LANDSCAPE</div> My iPhone 10XS shows as My 1920x1080 standard desktop (Chrome) shows |
Beta Was this translation helpful? Give feedback.
-
What's the nicest way to target a certain viewport but only in landscape? Do I have to create that specific media query in the config?.. or can it be combined? E.g |
Beta Was this translation helpful? Give feedback.
-
as of tailwind 3.0 you can use
|
Beta Was this translation helpful? Give feedback.
-
Perhaps solve this by adding a custom breakpoint like below. The use of (I have added an additional s to landscapeS in the below to make a custom additional breakpoint. You can probably also amend the existing one but I do not know how yet.)
|
Beta Was this translation helpful? Give feedback.
-
This is a syntax example of how to do it in Tailwind 4 css files:
|
Beta Was this translation helpful? Give feedback.
-
Anyone know the best way to deal with Mobile Landscape viewport in Tailwind eg. how to target it specifically?
Beta Was this translation helpful? Give feedback.
All reactions