0

Is it possible to access the screen's width and height in CSS Media queries, to write a dynamic url, like this:

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

Here width and height are variables, which would be dynamically set to whatever the user's width and height is.

Is that possible, or do I have to use javascript to accomplish this?

1 Answer 1

1

Not possible. CSS does not know anything about the environment.

Sign up to request clarification or add additional context in comments.

1 Comment

As an aside, you might like to look into a CSS framework like SASS - while it still doesn't know the window size, it does allow you to set variables and use them throughout the stylesheet as you have indicated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.