这可能吗?这似乎是一个整洁的解决方案,但我不知道它是否会有效。
- @media only screen
- and (min-device-width : 320px)
- and (max-device-width : 480px) {
- /* Code for both portrait and landscape */
- @media (orientation:portrait) {
- /* Code for just portrait */
- }
- @media (orientation:landscape) {
- /* Code for just landscape */
- }
- }
解决方法
您应该能够使用
nest
@media
rules this way in CSS3,但大多数浏览器尚未支持。详见
this answer。
您将不得不完全展开和重复顶级媒体查询内部规则,以便它可以在浏览器之间工作(我想像,SCSS处理器会产生类似的东西):
- @media only screen
- and (min-device-width: 320px)
- and (max-device-width: 480px) {
- /* Code for both portrait and landscape */
- }
- @media only screen
- and (min-device-width: 320px)
- and (max-device-width: 480px)
- and (orientation: portrait) {
- /* Code for just portrait */
- }
- @media only screen
- and (min-device-width: 320px)
- and (max-device-width: 480px)
- and (orientation: landscape) {
- /* Code for just landscape */
- }