0

I have something like this

<form class="Form">
  <FormField>
    <label class="FormLabel" ..>
    <div class="FormInput">
      <div class="InputField">
        <input../>
      </div>
    </div>
  </FormField>
</form>

I need to apply styles to FormLabel when input is focussed.
I understand that we cant get the parent selector(Is there a CSS parent selector?) I want a work around to access the parent using css only (not use jquery)

I tried this using & in LESS

.Form {
  .FormField {
    .Input:focus & .FormLabel {
       border:green
     }
   }
}

Still no luck :/ .. What am I missing? Thanks!

Community
  • 1
  • 1
suprita shankar
  • 1,274
  • 1
  • 12
  • 32

1 Answers1

2

There is no way, currently, to select the parent of an item using CSS. It must be done with JavaScript/jQuery.

Since there is no way to get the parent item of the item that's in focus (in this case, the input), you cannot change it's style using pure CSS.

mumbles
  • 38
  • 3