Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

(orientation: square), (orientation: portrait), and (orientation: landscape) on elements #6

Open
tomhodgins opened this issue Oct 11, 2016 · 2 comments

Comments

@tomhodgins
Copy link

One thing CSS does that's really cool is (orientation: portrait) and (orientation: landscape) on @media queries. I use them when building full-screen animations with vmin and vmax units to ensure that stuff never goes outside the viewport and it's really handy to have that kind of information available - but I wish I could do the same on elements.

I grabbed the source code of EQCSS from http://elementqueries.com this weekend and added the following bit of JavaScript:

// Orientation
case "orientation":

// Square Orientation
if (EQCSS.data[i].conditions[k].value === 'square'){
  if (!(elements[j].offsetWidth == elements[j].offsetHeight)){
    test = false;
    break test_conditions;
  }
}

// Portrait Orientation
if (EQCSS.data[i].conditions[k].value === 'portrait'){
  if (!(elements[j].offsetWidth < elements[j].offsetHeight)){
    test = false;
    break test_conditions;
  }
}

// Landscape Orientation
if (EQCSS.data[i].conditions[k].value === 'landscape'){
  if (!(elements[j].offsetHeight < elements[j].offsetWidth)){
    test = false;
    break test_conditions;
  }
}

And now syntax like this is supported on @element queries:

@element ".orientation" and (orientation: square) {
  $this {
    background: orchid;
  }
}
@element ".orientation" and (orientation: portrait) {
  $this {
    background: darkturquoise;
  }
}
@element ".orientation" and (orientation: landscape) {
  $this {
    background: greenyellow;
  }
}

So now this is working with EQCSS in all browsers IE8 and up. Here's a video of me testing this in IE8:

Code demos

I think it would be pretty cool if this was something normal CSS was aware of - I'll be able to put this to use right away!

@sebastienvermeille
Copy link

👍 we need it !

@luislobo14rap
Copy link

I do not know if it is valid, but in the case of window size, it would not be necessary to take the innerWidth / Height to know the screen size and not offset? To find the screen orientation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants