Css 如何在横向位置为HD/Retina显示编写媒体查询?
基本上,我想在移动设备上实现两种不同的风格。一套用于纵向视图,另一套用于横向视图。我在测试过程中遇到了一个问题,因为我的星系S4的分辨率很高,所以在纵向视图中,它显示的应该是我的横向视图。我的初始CSS编写如下Css 如何在横向位置为HD/Retina显示编写媒体查询?,css,media-queries,Css,Media Queries,基本上,我想在移动设备上实现两种不同的风格。一套用于纵向视图,另一套用于横向视图。我在测试过程中遇到了一个问题,因为我的星系S4的分辨率很高,所以在纵向视图中,它显示的应该是我的横向视图。我的初始CSS编写如下 #checkoutoptions { border: 2px solid #c6c6c6; border-radius: 10px; padding: 10px; position: relative; } #checkoutoptions h3 {
#checkoutoptions {
border: 2px solid #c6c6c6;
border-radius: 10px;
padding: 10px;
position: relative;
}
#checkoutoptions h3 {
font-size: 1.2em;
font-weight: 500;
margin-left: 35px;
margin-top: 10px;
}
#checkoutoptions h4 {
color: #000;
font-size: 1.2em;
font-weight: 600;
margin-bottom: 0;
}
#checkoutoptions p {
font-size: .8em;
margin-bottom: 5px;
}
#checkoutoptions .label {
display: inline-block;
font-size: .9em;
margin: 10px 0 20px;
}
#checkoutoptions .input {
border: 1px solid #eee;
border-radius: 5px;
box-shadow: 0 0 0 4px #f4f4f4;
font-size: 1em;
height: 2.25em;
margin-top: 10px;
}
#checkoutoptions .number {
background-color: #c6c6c6;
border-radius: 15px;
color: #fff;
height: 30px;
line-height: 30px;
position: absolute;
text-align: center;
top: 15px;
width: 30px;
}
#checkoutoptions .dividingLine {
border-bottom: 1px solid #c6c6c6;
padding-bottom: 10px;
}
#checkoutoptions #signin {
border-bottom: 1px solid #c6c6c6;
padding-bottom: 10px;
}
#checkoutoptions .forgotpassword {
font-size: .75em;
margin-top: 15px;
}
@media only screen and (min-width: 321px){
#checkoutoptions {
overflow: auto;
}
#signin {
float: left;
clear: both;
width: 45%;
}
.registeroptions {
float: left;
position: relative;
width: 50%;
}
#checkoutoptions #signin {
border-bottom: 0;
padding-bottom: 0;
border-right: 1px solid #c6c6c6;
margin-right: 10px;
}
}
通过一些研究,我发现HD/Retina屏幕上有媒体查询。因此,我添加了以下内容:
@media
only screen and (-webkit-min-device-pixel-ratio: 1.25),
only screen and ( min--moz-device-pixel-ratio: 1.25),
only screen and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and ( min-device-pixel-ratio: 1.25),
only screen and ( min-resolution: 200dpi),
only screen and ( min-resolution: 1.25dppx)
{
#checkoutoptions {
overflow: auto;
}
#signin {
float: none;
clear: both;
width: 100%;
}
.registeroptions {
float: none;
position: relative;
width: 100%;
}
#checkoutoptions #signin {
border-right: 0;
margin-right: 0;
border-bottom: 1px solid #c6c6c6;
padding-bottom: 10px;
}
}
这对于让我的高清屏幕完全按照我的要求显示纵向视图非常有用。下一步,景观!这当然是我遇到死胡同的地方。我还没有找到一个对我有用的查询,而且到目前为止,研究还没有就此展开任何讨论。对于如何为横向HD/Retina设备编写适当的媒体查询,有什么想法吗
到目前为止我已经尝试过的事情:
@media
only screen and (min-width; 1081px) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (min-width; 1081px) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (min-width; 1081px) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (min-width; 1081px) and ( min-device-pixel-ratio: 1.25),
only screen and (min-width; 1081px) and ( min-resolution: 200dpi),
only screen and (min-width; 1081px) and ( min-resolution: 1.25dppx)
{
#checkoutoptions {
overflow: auto;
}
#signin {
float: left;
clear: both;
width: 45%;
}
.registeroptions {
float: left;
position: relative;
width: 50%;
}
#checkoutoptions #signin {
border-bottom: 0;
padding-bottom: 0;
border-right: 1px solid #c6c6c6;
margin-right: 10px;
}
}
目前正在运行(可能需要更多测试):
/* Portrait View */
@media
only screen and (max-width: 360px) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (max-width: 360px) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (max-width: 360px) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (max-width: 360px) and ( min-device-pixel-ratio: 1.25),
only screen and (max-width: 360px) and ( min-resolution: 200dpi),
only screen and (max-width: 360px) and ( min-resolution: 1.25dppx)
{
/* Styles */
}
/* Landscape View */
@media
only screen and (min-width: 361px) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (min-width: 361px) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (min-width: 361px) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (min-width: 361px) and ( min-device-pixel-ratio: 1.25),
only screen and (min-width: 361px) and ( min-resolution: 200dpi),
only screen and (min-width: 361px) and ( min-resolution: 1.25dppx)
{
/* Styles */
}
您可以在媒体查询中使用
方向:横向
,而不是最小宽度
:
@media
only screen and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (orientation:landscape) and ( min-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( min-resolution: 200dpi),
only screen and (orientation:landscape) and ( min-resolution: 1.25dppx)
{
您可以在媒体查询中使用
方向:横向
,而不是最小宽度
:
@media
only screen and (orientation:landscape) and (-webkit-min-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( min--moz-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( -o-min-device-pixel-ratio: 1.25/1),
only screen and (orientation:landscape) and ( min-device-pixel-ratio: 1.25),
only screen and (orientation:landscape) and ( min-resolution: 200dpi),
only screen and (orientation:landscape) and ( min-resolution: 1.25dppx)
{
我要试一试。我最初只是用
orientation:scape
编写了查询,因为这样做只会让事情变得更简单。不幸的是,在我的一些测试设备上,当我选择一个
字段时,软键盘在纵向模式下弹出,这改变了视图字段,足以翻转到方向:横向
样式,尽管没有足够的空间。啊,我明白了,我以前也遇到过这种情况。我很确定我必须使用min/max设备宽度
而不是min/max宽度
以及orientation
。我只是尝试插入orientation:landscape
,问题依然存在。接下来我将给min/max device width
一个镜头。使用max device width
或min device width
和方向:横向
在大部分情况下都有效。令人恼火的是,它不能解决软键盘问题。我来试试。我最初只是用orientation:scape
编写了查询,因为这样做只会让事情变得更简单。不幸的是,在我的一些测试设备上,当我选择一个
字段时,软键盘在纵向模式下弹出,这改变了视图字段,足以翻转到方向:横向
样式,尽管没有足够的空间。啊,我明白了,我以前也遇到过这种情况。我很确定我必须使用min/max设备宽度
而不是min/max宽度
以及orientation
。我只是尝试插入orientation:landscape
,问题依然存在。接下来我将给min/max device width
一个镜头。使用max device width
或min device width
和方向:横向
在大部分情况下都有效。令人烦恼的是,它不能解决软键盘问题。