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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:09:20+00:00 2026-06-13T22:09:20+00:00

I need to fill a <LI> width element with his most left child (out

  • 0

I need to fill a <LI> width element with his most left child (out of three childs). Those three childs are formated with display: inline-block; float: right.

what i achieved so far:

enter image description here

what i expected to achieve:

enter image description here

It’s obviously that width: 66% don’t help anyway. Also a 100% width will not work.

I found this question on stackoverflow, but I need something made in pure CSS, no JS, jQuery, etc. Also, using a table is not a solution for me.

If the HTML code can help in this matter:

<style type="text/css">
    div {
        width: 200px;
        border: 1px solid red;
    }
    ul {
        padding: 0px 0px 0px 20px;
        margin: 0px;
    }
    li {
        display: block;
        white-space: nowrap;
        list-style-type: none;
        display: block;
        height: 20px;
        padding: 0px;
        margin: 1px;
        -moz-border-radius: 3px;
        -webkit-border-radius: 3px;
        border-radius: 3px;

        border-color: #D5AB55 #C93 #C93 #D5AB55;
        background-color: #F3CE00;
    }

    .name {
        display: inline-block;
        float: right;
        height: 18px;
        width: 65%;
        margin: 0px;
        padding: 0px 2px;
        border: 1px solid grey;
        -moz-border-radius: 3px;
        -webkit-border-radius: 3px;
        border-radius: 3px;
    }
    .save, .cancel {
        display: inline-block;
        float: right;
        height: 20px;
        width: 20px;
        margin: 0px 0px 0px 1px;
        padding: 0px;
        border: 1px solid grey;
        -moz-border-radius: 3px;
        -webkit-border-radius: 3px;
        border-radius: 3px;
    }
    .save   { background: url(../images/confirm.png) no-repeat center center; }
    .cancel { background: url(../images/cancel.png) no-repeat center center; }
</style>

<div>
    <ul>
        <li>
            <input type="button" value="" class="cancel">
            <input type="button" value="" class="save">
            <input type="text" value="Big list item" class="name">
        </li>
        <ul>
            <li id="category_2" id_category="2">
                <input type="button" value="" class="cancel">
                <input type="button" value="" class="save">
                <input type="text" value="Medium list item" class="name">
            </li>
            <ul>
                <li>
                    <input type="button" value="" class="cancel">
                    <input type="button" value="" class="save">
                    <input type="text" value="1st small item" class="name">
                </li>
                <li>
                    <input type="button" value="" class="cancel">
                    <input type="button" value="" class="save">
                    <input type="text" value="2nd small item" class="name">
                </li>
                <li>
                    <input type="button" value="" class="cancel">
                    <input type="button" value="" class="save">
                    <input type="text" value="3rd small item" class="name">
                </li>
            </ul>
        </ul>
    </ul>
</div>

Thanks for your time,

SYNCRo,

  • 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-13T22:09:22+00:00Added an answer on June 13, 2026 at 10:09 pm

    Having corrected your invalid HTML (as noted in the comment to your question no element other than an li is a valid child of a ul or ol, including those elements themselves) to the following:

    <div>
        <ul>
            <li class="items">
                <input type="button" value="" class="cancel" />
                <input type="button" value="" class="save" />
                <input type="text" value="Big list item" class="name" />
            </li>
            <li>
            <ul>
                <li id="category_2" id_category="2" class="items">
                    <input type="button" value="" class="cancel" />
                    <input type="button" value="" class="save" />
                    <input type="text" value="Medium list item" class="name" />
                </li>
                <li>
                <ul>
                    <li class="items">
                        <input type="button" value="" class="cancel" />
                        <input type="button" value="" class="save" />
                        <input type="text" value="1st small item" class="name" />
                    </li>
                    <li class="items">
                        <input type="button" value="" class="cancel" />
                        <input type="button" value="" class="save" />
                        <input type="text" value="2nd small item" class="name" />
                    </li>
                    <li class="items">
                        <input type="button" value="" class="cancel" />
                        <input type="button" value="" class="save" />
                        <input type="text" value="3rd small item" class="name" />
                    </li>
                </ul>
                </li>
            </ul>
            </li>
        </ul>
    </div>
    

    Note that I had to add a class to those li elements that contain children (since the previous, simple, li selector now matches the multiple elements in the hierarchy), in this case the class items, but adjust to taste.

    The following CSS works, albeit only with a pretty up-to-date browser:

    li {
        width: 80%;
        clear: both;
        float: right;
        margin: 0 0 0.2em 0;
    }
    
    li.items {
        background-color: #f90;
    }
    
    li .save, li .cancel {
        float: right;
        width: 20px;
        height: 20px;
    }
    
    input.name {
        width: -webkit-calc(100% - 45px);
        width: -moz-calc(100% - 45px);
        width: -o-calc(100% - 45px);
        width: -ms-calc(100% - 45px);
        width: calc(100% - 45px);
    }
    

    JS Fiddle demo.

    This uses the CSS calc() function to determine the width of the input element as a calculation.

    To be cross-browser compatible with the older browsers you could use, instead, absolute (for the .save and .cancel elements) and relative (for the li elements) positioning:

    li {
        width: 80%;
        clear: both;
        float: right;
        margin: 0 0 0.2em 0;
        position: relative;
    }
    
    li.items {
        background-color: #f90;
        padding: 0 45px 0 0;
    }
    
    li .save, li .cancel {
        position: absolute;
        width: 20px;
        height: 20px;
    }
    
    .save {
        top: 0;
        right: 21px;
    }
    
    .cancel {
        top: 0;
        right: 0;
    }
    
    input.name {
        width: 100%;
    }
    

    JS Fiddle demo.

    You’ll note that the padding gets added to the width of the li elements, of course, so you may wish to add the box-sizing CSS property to compensate for that:

    /* all other CSS remains untouched */
    li {
        width: 80%;
        clear: both;
        float: right;
        margin: 0 0 0.2em 0;
        position: relative;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
        -o-box-sizing: border-box;
        box-sizing: border-box;
    }
    

    JS Fiddle demo.

    References:

    • CSS box-sizing.
    • CSS calc().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to fill a stack from an array, then print out the elements
I need to fill a rectangle with a black to white (transparent) gradient. However,
Starting with an empty dataframe, I need to fill the dataframe as follows: A
I have a List[Option[MyClass]] with None in random positions and I need to 'fill'
For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1);
I need to guess the mime type with the purpose of fill the Content-Type
Some of my columns need explicit widths, while others should just fill up all
I need to fill textboxes depending on the item selected in a combobox. I
I need to know the information when i fill the form and then submit
I need to do: I am using the normal auto-fill function in Excel (double

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.