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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:42:15+00:00 2026-05-29T14:42:15+00:00

I have a series of LI inside a UL like this: <ul> <li class=section

  • 0

I have a series of LI inside a UL like this:

<ul>
    <li class="section left"></li>
    <li>I want to float this on the left</li>
    <li>I want to float this on the left</li>
    <li>I want to float this on the left</li>
    <li class="section right"></li>
    <li>I want to float this on the right</li>
    <li>I want to float this on the right</li>
    <li>I want to float this on the right</li>
</ul>

This HTML is generated by php and I cannot alter the HTML, on the other hand I have the ability to assign classes to individual LI elements. The UL and LIs will contain form elements, which I want to distribute in two sections, floating some contents (some LIs) on the left and some content (other LIs) on the right.

If I could nest ULs within the main UL this would be much easier, treating inner ULs as blocks, but I can’t do that here.

How to accomplish the same result with CSS given the HTML constraints mentioned above? I mean yeah I could assign floating classes individually to each LI but I was hoping to a more elegant solution here.

thank you

  • 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-29T14:42:16+00:00Added an answer on May 29, 2026 at 2:42 pm

    Add the following CSS3 code:

    ul{width:100%;list-style:none;}
    /* the '~'  (general sibling combinator)
     * selector will select all following siblings in the document tree.
     * This selector is part of the CSS3 selector recommendation,
     * see also http://www.w3.org/TR/selectors/#general-sibling-combinators
     *
    */
    li.section.left, li.section.left ~ li{
        background-color:#faa;
        float:left;
        margin-right:1em;
    }
    li.secton.right , li.section.right ~ li{
        background-color:#afa;
        float:right ;
        margin-left:1em;
        margin-right:0;
    }
    

    Use this with your proposed code and you’ll get what you need (at least in decent browsers). JSFiddle Demo / Demo with small font size (to see effect)

    Update: IE7+ compatible version (simply without :not)

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

Sidebar

Related Questions

Let's say I have a series of elements designed to render via float:left inside
I have a series of nested UL's that are like this: <ul class=categorySelect id=>
I have a series of PHP page, and I would like to use conditional
I have a series of if statements in a function like this: if time
I have a series of <div class=clear-both></div> after a series of divs. I want
I have a series of data that I want to put inside an array
This feels like an extremely n00b question, but here goes... I have a series
I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those
I have a series of controls on an ASP page. Some are inside an
I have a series of... pseudo-xml files. What I mean by this, is they

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.