访问CSS媒体查询中的屏幕宽度和高度

Accessing the screen width and height in CSS Media Queries?

本文关键字:高度 屏幕 CSS 媒体 查询 访问      更新时间:2023-09-26

是否可以在CSS媒体查询中访问屏幕的宽度和高度,以编写动态url,如以下所示:

@media all
{
    background: url("http://site.com/background/" + width + "/" + height");
}

这里宽度和高度是变量,可以动态设置为用户的宽度和高度

这可能吗?或者我必须使用javascript来完成这一任务吗?

不可能。CSS对环境一无所知。