Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7899445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:42:16+00:00 2026-06-03T08:42:16+00:00

I have a form where I placed my labels before inputs like this: <label

  • 0

I have a form where I placed my labels before inputs like this:

<label for="email">Confirm Email</label>
<input type="text" id="email" />
<label for="firstname">First Name</label>
<input type="text" id="firstname" />
<label for="lastname">Last Name</label>
<input type="text" id="lastname" />
<label for="company">Company</label>
<input type="text" id="company" />

When I try to use the CSS to style the label, when I hover the inputs like this (input:hover + label), the CSS applies on the next label instead on the one that has the for= property. For example, if I try to hover the email input, it will apply the input:hover+label effect on the 2nd label with for="firstname".

My design structure has labels on top and inputs under them, so I can’t switch their position.

Is there any solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:42:17+00:00Added an answer on June 3, 2026 at 8:42 am

    With some clever CSS you can have the label after the input, but still have the label look like it’s on top of the input http://jsfiddle.net/8YqN2/2/

    <input type="text" id="email" />
    <label for="email">Confirm Email</label>    
    <input type="text" id="firstname" />
    <label for="firstname">First Name</label>    
    <input type="text" id="lastname" />
    <label for="lastname">Last Name</label>    
    <input type="text" id="company" /> 
    <label for="company">Company</label>
    

    CSS

    input:hover + label  {
      background-color: #eee;
    }
    
    input {
      position: relative;
      display: block;
      margin-top: 1.5em;
    }
    
    label {
      display: block;
      position: relative;
      top: -2.5em;
    }
    

    I don’t think this is possible with CSS alone, if you can live with the effect for users with JS enabled, you can use the following. http://jsfiddle.net/8YqN2/1/

    $('input').hover(
      function(){
        $(this).prev().addClass('hover');
      },
      function(){
        $(this).prev().removeClass('hover');
      }
    );
    
    label.hover  {
      background-color: #eee;
    } ​
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form with multiple input type=radio with text next to them. I want
I have placed a form on a page which looks like this: <form id=editClassList
I have a form panel and i want text fields stick to their labels
I have a simple html form. On php page. A simple list is placed
I have form, where some fields are looks like rows, so I can add/delete
I have form in my page, I am using ajax.beginform(). Inside this form I
i have form with user data to input and javascript ajax to send information
I have a form that has an array of dynamically created labels of varying
I have a client that wants a WYSIWYG form that behaves like MS word.
I have HTML form with lots of select and input fields, using it a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.