0

I am trying affect the label whenever the input is focused. For whatever reason the css isnt being recognized for the label whenever the input is focused.

li.sm-vol label {
    position: absolute;
    top: 33px;
    width: 100%;
    background: #462770;
    color: #fff;
    font-weight: 400 !important;
    padding-left: 10px;
    transition: all 0.2s ease;
}

li.sm-vol input:focus li.sm-vol label {
    top: 15px;
}
2
  • 1
    Could you add the HTML as reference? It would help understand the code and how it behaves. Commented Jun 9, 2016 at 15:03
  • meta.stackexchange.com/q/5234 Commented Jul 14, 2016 at 15:14

1 Answer 1

4

You can do it with pure CSS only if the label is next to the input field by using + or ~ selector, i.e.

input:focus + label {
  color: red;
}
<input type="text">
<label>Label</label>

For visually reordering the input and label positions, see the simple demo with flexbox.

.fieldset {
  display: inline-flex;
}
.fieldset label {
  order: -1;
  margin-right: 4px;
}
.fieldset input:focus + label {
  color: red;
}
<div class="fieldset">
  <input type="text">
  <label>Label</label>
</div>

Sign up to request clarification or add additional context in comments.

Comments

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.