Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS如果其他条件、移动纵向或横向_Css_Media Queries_Orientation - Fatal编程技术网

CSS如果其他条件、移动纵向或横向

CSS如果其他条件、移动纵向或横向,css,media-queries,orientation,Css,Media Queries,Orientation,如何在高度条件下使用。没有javascript @media (calc(window-width > window-height)) { background-color: lightblue; } @media (calc(window-width <= window-height)) { background-color: lightgray; } @媒体(计算(窗口宽度>窗口高度)){ 背景颜色:浅蓝色; } @媒体(计算)(

如何在高度条件下使用。没有javascript

@media (calc(window-width > window-height)) {
    background-color: lightblue;
}
@media (calc(window-width <= window-height)) {
    background-color: lightgray;                
}
@媒体(计算(窗口宽度>窗口高度)){
背景颜色:浅蓝色;
}
@媒体(计算)(窗口宽度尝试以下操作:

.something {
    background-color: lightblue;
}

@media (orientation: landscape) { 
    .something {
        background-color: lightgray;
    }
}

可以使用方向约束:

@media handheld and (orientation: landscape) {
    /* applies to mobiles in landscape mode */
}
@media handheld and (orientation: portrait) {
    /* applies to mobiles in portrait mode */
}
多个规则以逗号分隔(
),否则使用

请参阅。

方向

价值:风景|肖像

媒体:视觉

接受最小/最大前缀:否

指示视口是否处于横向(显示更宽) 比它高)或纵向(显示器比它宽) 模式

示例

要仅以纵向方向应用样式表,请执行以下操作:

@media all和(方向:纵向){…}

注意:此值不适用 与实际设备方向不一致。打开软键盘 在大多数设备上,纵向将导致视口 变得比其高度更宽,从而导致浏览器使用 风景画而不是肖像画


不能使用calc方法,因为calc方法是css属性的值而不是属性

但您可以将媒体规则与“最大宽度”和“最小宽度”相结合(粘贴宽度或高度值,而不是xxx):

您还可以使用更高级的媒体查询,如下所示:

@media all and (max-width: xxx) and (min-width: xxx), (min-width: xxx) {}
/* Portrait */
@media screen and (orientation:portrait) {
    /* Portrait styles */
}
/* Landscape */
@media screen and (orientation:landscape) {
    /* Landscape styles */
}
如果您尝试使用肖像和风景画,那么您可以这样做:

@media all and (max-width: xxx) and (min-width: xxx), (min-width: xxx) {}
/* Portrait */
@media screen and (orientation:portrait) {
    /* Portrait styles */
}
/* Landscape */
@media screen and (orientation:landscape) {
    /* Landscape styles */
}

这就是我们的全部资料。

您也可以将媒体查询与
高度一起使用-

比如说-

@media screen and (max-width: 995px) , screen and (max-height: 700px) {
  ...
}
或者,您可以使用with-orientation

你也可以和身高搭配使用

@media (max-height: 700px), handheld and (orientation: landscape) { ... }
我的一些朋友也发布了MDN URL,你可以从中获得更多信息


这对你很有用

有人能说一下如何在Safary浏览器中使用css代码吗:@media(最小宽度:150vh){.imageMap{height:100%;width:150vh;背景色:浅蓝色;}}@media(最大宽度:150vh){.imageMap{width:100%;height:66vw;背景色:浅灰色;}