-3

I'm trying to do something similar with this example by using the "checked" hack

input[type=checkbox]:checked ~ label .box { 
  opacity:0;
  -webkit-transform   :scale(0) rotate(-180deg);
  -moz-transform      :scale(0) rotate(-180deg);
  transform           :scale(0) rotate(-180deg);
}

http://codepen.io/anon/pen/KVWWjy

However, I need to change the html code so that the label tag is before the input tag. When I move the input in the bottom the effects stop working. how can I fix this?

cimmanon
  • 67,211
  • 17
  • 165
  • 171

2 Answers2

0

There is no previous sibling selector in CSS. If it there was, CSS would be a lot slower. There has been a lot of debate on this subject and it won't happen in any foreseeable future.

As chowey very well put it:

CSS selectors are designed to be easy (fast) to implement for the browser. The document can be traversed once, matching elements as you go, with no need to ever go backward to adjust a match

Simply put, you'll have to change your markup. You can't make CSS look backwards. It only looks forward.

For more info on the subject, see this question.

Community
  • 1
  • 1
tao
  • 82,996
  • 16
  • 114
  • 150
0

With css this is impossible as you cannot traverse up, the selector you use only looks at the next siblings it dosent work backwards. For this to work you'd have to use Javascript.

Antonio Smoljan
  • 2,187
  • 1
  • 12
  • 11