基本上我有两种不同的风格,我想在移动设备上制定。一组用于纵向视图,另一组用于横向。我在测试过程中遇到了一个问题,因为我的 Galaxy S4 在纵向视图中显示应该是我的横向视图,因为它的分辨率很大。我的初始 CSS 编写如下。
#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;
}
}
这非常适合让我的高清屏幕完全按照我的意愿显示纵向视图。下一个,景观视图!这当然是我遇到了死胡同的地方。我还没有想出一个对我有用的查询,到目前为止,研究还没有对此进行任何讨论。关于如何为 Landscape 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 */
}