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 7683203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:44:30+00:00 2026-05-31T18:44:30+00:00

I have looked at the different questions regarding this issue, but couldn’t find anything

  • 0

I have looked at the different questions regarding this issue, but couldn’t find anything that works due to limitations in my markup.

My markup looks like so (unfortunately as this is generated by some backend, I am unable to change the markup).

<ul>        
    <li>
        <input type="checkbox" value="1" name="test[]" id="myid1">
        <label for="myid1">label1</label>
    </li>
    <li>
        <input type="checkbox" value="2" name="test[]" id="myid2">
        <label for="myid2">label1</label>
    </li>
</ul>

I need the checkbox to be on the right and centered vertically in the <li>

Currently, this is styled as:

li input{
   display: inline-block;
   float: right;
   margin-right: 10px;
}

I have tried using various values for vertical-align, but that doesn’t seem to help. Also, in some cases the label can be very long and span multiple lines. The checkbox would still need to be able to vertically center itself when the height of the li is arbitrary.

How can I go about achieving 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-05-31T18:44:32+00:00Added an answer on May 31, 2026 at 6:44 pm

    Vertical alignment only works on inline elements. If you float it, then I don’t think it is treated as part of that stream of inline elements any more.

    Make the label an inline-block, and use vertical alignment on both the label and the input to align their middles. Then, assuming it is okay to have a specific width on the labels and checkboxes, use relative positioning instead of floating to swap them (jsFiddle demo):

    input {
        width: 20px;
    
        position: relative;
        left: 200px;
             
        vertical-align: middle;
    }
    
    label {  
        width: 200px;
        
        position: relative;
        left: -20px;
        
        display: inline-block;
        vertical-align: middle;
    }
    

    2024 update, using Flexbox (fiddle):

    ul {
      width: 300px; /* Only for demonstration. */
      border: 1px dashed gray;
    }
    
    li {
        display: flex;
        flex-direction: row-reverse; /* Only needed for swapping their order. */
        align-items: center;
    }
    
    input {
        background-color: blue;
    }
    
    label {
        background-color: red;
        flex-grow: 1; /* Grow the label to fill available space, pushing the checkboxes to the edge of the container. */
    }
    

    Less hacky, and with this you don’t need to specify any widths. It will grow to fill the container, and wrap if necessary.

    Another alternative would be Flexbox Grid.

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

Sidebar

Related Questions

I have looked around and was unable to find any questions regarding this exact
I have looked for similar questions, but could find none other than the difference
I have looked at many different peoples answers to this problem but they only
I have looked at this a bunch of different ways and with what little
Have looked quite hard for this answer but having no luck. I have 3
I have looked at questions like this , this , this and this ,
I have looked at many of the other questions but I think my problem
I've looked through numerous similar questions here at SO, but nothing helps. I have
I have looked through lots of similar questions, and I have found out that
Disclaimer: I have looked through this question and this question but they both got

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.