0

There is a div element and its size (both width and height) depends on its content. The content is loaded dynamically, so sometimes div width is greater than height and sometimes otherwise.

Is it possible to set different backgrounds in CSS for the case when width > height and for the case when width < height without JS?

I mean something like orientation media query, but for a given element, not the whole screen.

Shtole
  • 77
  • 6

1 Answers1

1

For what I understand you want something like this:

.box {
  min-height:50px;
  margin:10px;
  border:1px solid;
  background:
    linear-gradient(green,green)   left/calc(100% - 800px) 100%,
    linear-gradient(yellow,yellow) left/calc(100% - 600px) 100%,
    red;
}
<div class="box"></div>

So basically and in this specific case, if the DIV is more than 800px, the color will be green, between 600 and 800px yellow and less than 600px will be red.

Hope I helped.