0

I'm curious if I can use CSS to target the first url syntax below if a user is below a certain screen width.

For example, if a user's browsers is below 700px, I do not want to show the first background image (background.png) - just the second (background1.jpg).

<div class="right-header" style="background-image: url('/wp-content/uploads/2020/11/background.png'), url('/wp-content/uploads/2020/11/background1.jpg');">

1 Answer 1

3

you can use media queries for that:

In your CSS file:

.right-header {
    background-image: url('/wp-content/uploads/2020/11/background.jpg');
}

@media screen and (max-width: 700px) {
  .right-header {
      background-image: url('/wp-content/uploads/2020/11/background1.jpg');
  }
}

And in your HTML:

<div class="right-header"></div>
Sign up to request clarification or add additional context in comments.

1 Comment

By the way, in your code, you are using an inline CSS, is highly recommended to use an external CSS file, link it with the link HTML tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.