html - 浏览器的地址栏尺寸会影响 CSS 媒体查询吗?

标签 html css media-queries responsiveness

当我为我的网站编写媒体查询时,我想到了这个: 浏览器的地址栏会影响 CSS 媒体查询吗?

当我编写代码时:

/* Portrait */
@media screen 
  and (device-width: 320px) 
  and (device-height: 640px)  
  and (orientation: portrait) {

}

我是否在考虑浏览器地址栏的高度? 地址栏会减去屏幕视口(viewport)的像素吗?

我必须考虑这个媒体查询吗?

/* Portrait */
@media screen 
  and (device-width: 320px - <AddressBarHeight>) 
  and (device-height: 640px - <AddressBarHeight>)  
  and (orientation: portrait) {

}

最佳答案

device-heightdevice-width 与屏幕上显示的内容无关。它们仅反射(reflect)整个屏幕的整体尺寸。

device-width

The ‘device-width’ media feature describes the width of the rendering surface of the output device. For continuous media, this is the width of the screen. For paged media, this is the width of the page sheet size.

device-height

The ‘device-height’ media feature describes the height of the rendering surface of the output device. For continuous media, this is the height of the screen. For paged media, this is the height of the page sheet size.

Media Queries W3C Recommendation

例子

例如,我使用的是 1920x1080 像素的显示器。使用针对恰好 1920 像素的 device-width 和恰好 1080px 的 device-height 的媒体查询,下面的代码片段在我的显示器上将显示红色背景,即使虽然片段本身被限制在一个更小的区域 (660x201px):

@media (device-width: 1920px) and (device-height: 1080px) {
  body {
    background: red;
  }
}

结果(图片)

What I see

关于html - 浏览器的地址栏尺寸会影响 CSS 媒体查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30054364/

相关文章:

jquery UI 禁用主题样式

css - :active different from :hover时的样式按钮

css - 旋转谷歌地图容器而不是 map 本身

html - 为什么我的@media 屏幕不保存

html - 用CSS background-image模拟按钮效果?

javascript - 在 IE 中单击小部件内的滚动条时,Gridster 小部件会粘在鼠标上

css - 如何创建每页两列打印布局?

css - 使用媒体查询渐进式加载图像

html - 在 div 上填充在前面的 div 媒体查询上创建边距

html - 如何在jsp中将整个文本向下移动?