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:

what i expected to achieve:

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,
Having corrected your invalid HTML (as noted in the comment to your question no element other than an
liis a valid child of aulorol, including those elements themselves) to the following:Note that I had to add a class to those
lielements that contain children (since the previous, simple,liselector now matches the multiple elements in the hierarchy), in this case the classitems, but adjust to taste.The following CSS works, albeit only with a pretty up-to-date browser:
JS Fiddle demo.
This uses the CSS
calc()function to determine the width of theinputelement as a calculation.To be cross-browser compatible with the older browsers you could use, instead, absolute (for the
.saveand.cancelelements) and relative (for thelielements) positioning:JS Fiddle demo.
You’ll note that the
paddinggets added to the width of thelielements, of course, so you may wish to add thebox-sizingCSS property to compensate for that:JS Fiddle demo.
References:
box-sizing.calc().