如何在CSS中设置纵向和横向媒体查询?

UI_*_*Dev 29 html css media-queries

这是我的媒体查询:

@media screen and (min-device-width: 768px) and (max-device-width: 1824px) and (orientation : portrait){
  .hidden-desktop {
    display: inherit !important;
  }
  .visible-desktop {
    display: none !important ;
  }
  .visible-tablet {
    display: inherit !important;
  }
  .hidden-tablet {
    display: none !important;
  }
}

@media screen and (min-device-width: 768px) and (max-device-width: 1824px) and (orientation : landscape){
  .hidden-desktop {
    display: inherit !important;
  }
  .visible-desktop {
    display: none !important ;
  }
  .visible-tablet {
    display: inherit !important;
  }
  .hidden-tablet {
    display: none !important;
  }
}
@media screen and (max-device-width: 767px) and (orientation: portrait) {
  .hidden-desktop {
    display: inherit !important;
  }
  .visible-desktop {
    display: none !important;
  }
  .visible-phone {
    display: inherit !important;
  }
  .hidden-phone {
    display: none !important;
  }
}
@media screen and (max-device-width: 767px) and (orientation: landscape) {
  .hidden-desktop {
    display: inherit !important;
  }
  .visible-desktop {
    display: none !important;
  }
  .visible-phone {
    display: inherit !important;
  }
  .hidden-phone {
    display: none !important;
  }
} 
Run Code Online (Sandbox Code Playgroud)

但在平板电脑中,如果它处于横向模式,则显示此div

 .visible-tablet {
    display: inherit !important;
  }
Run Code Online (Sandbox Code Playgroud)

如果处于纵向模式,则显示此div

.visible-phone {
    display: inherit !important;
  }
Run Code Online (Sandbox Code Playgroud)

.visible-tablet每当我将平板电脑切换到自动旋转模式(这将是纵向和横向)时,我希望这个div 始终显示

但我使用了肖像和风景条件,但我仍然面临着这个问题.任何意见?

KiV*_*KiV 34

iPad媒体查询(所有世代 - 包括iPad mini)

由于Apple致力于为用户创造一致的体验,并为开发人员提供便利的时间,所有5种不同的iPad(iPad 1-5和iPad mini)都可以通过一个CSS媒体查询进行定位.接下来的几行代码应该适用于响应式设计.

iPad的纵向和横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)  { /* STYLES GO HERE */}
Run Code Online (Sandbox Code Playgroud)

iPad在风景中

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) { /* STYLES GO HERE */}
Run Code Online (Sandbox Code Playgroud)

iPad在纵向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) { /* STYLES GO HERE */ }
Run Code Online (Sandbox Code Playgroud)

iPad 3和4媒体查询

如果您希望仅针对第3代和第4代Retina iPad(或具有类似分辨率的平板电脑)为平板电脑的Retina显示屏添加@ 2x图形或其他功能,请使用以下媒体查询.

Retina iPad的纵向和横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 2) { /* STYLES GO HERE */}
Run Code Online (Sandbox Code Playgroud)

Retina iPad在风景中

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 2) { /* STYLES GO HERE */}
Run Code Online (Sandbox Code Playgroud)

Retina iPad的肖像

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio: 2) { /* STYLES GO HERE */ }
Run Code Online (Sandbox Code Playgroud)

iPad 1和2媒体查询

如果您希望为较低分辨率的iPad显示屏提供不同的图形或选择不同的排版,下面的媒体查询将像您的响应式设计中的魅力一样!

iPad 1和2的纵向和横向

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (-webkit-min-device-pixel-ratio: 1){ /* STYLES GO HERE */}
Run Code Online (Sandbox Code Playgroud)

iPad 1和2在风景中

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 1)  { /* STYLES GO HERE */}
Run Code Online (Sandbox Code Playgroud)

iPad 1和2的肖像

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) 
and (-webkit-min-device-pixel-ratio: 1) { /* STYLES GO HERE */ }
Run Code Online (Sandbox Code Playgroud)

资料来源:http://stephen.io/mediaqueries/

  • 问题不是要求ipad的媒体查询.它特别说肖像和风景,其中包括比ipad更多的设备. (5认同)
  • Apple用户只能看到世界上的Apple设备.这应该是非常明显的.据他们说,世界上不应该存在其他设备. (5认同)
  • 用于智能手机? (2认同)

que*_*ful 16

它也可以这么简单.

@media (orientation: landscape) {

}
Run Code Online (Sandbox Code Playgroud)

  • 请记住,这将适用于宽高比高的宽高比的所有东西,也就是最现代的屏幕.如果你很酷,那么这个媒体查询是完美的.找到这个代码,它演示了这个:https://codepen.io/CrisMVP3200/pen/BmBaZy (5认同)
  • @korona只是想清楚这会影响笔记本电脑的屏幕以及手机/平板电脑.就个人而言,我倾向于以移动方式思考风景和肖像,但这实际上只是比高大的任何东西...... (3认同)
  • @srussking 您还期望什么其他行为? (2认同)