views:

472

answers:

4
<div style="width: 300px">
<div id="one" style="float: left">saved</div><input type="submit" id="two" style="float: right" value="Submit" />
</div>

I would like div#one to be centred in the space between the left edge of the parent div and the left edge of the submit button.

+1  A: 

There are a number of techniques listed here

However, if you simply wanted the "saved" text to be centred, I think you'll need to give a width to #one, e.g.

<div style="width: 300px">
<div id="one" style="float: left;text-align:center;width:80%">saved</div>
<input type="submit" id="two" style="float: right;width:20%" value="Submit" />
</div>
Paul Dixon
A: 

That page doesn't apply to my problem.

Steve
write this sort of response in a comment on the question you're referring to. (though you mightn't have had the rep to do it before, you do now)
nickf
+1  A: 

A few more ways to do it:

        <div style="width: 300px">
            <input type="submit" id="two" style="float: right" value="Submit" />
            <div id="one" style="text-align:center;">
                saved</div>
        </div>

Its hard to tell that "saved" isn't centered between the left edge of the container div and the left edge of the submit button.

An exact version of the above:

<div style="width: 300px">
    <input type="submit" id="two" style="float: right; width:64px;" value="Submit" />
    <div id="one" style="text-align:center;margin-right:64px;">saved</div>
</div>
Will
that first example worked in my tests.
nickf
The first example works. :) Cheers.
Steve
A: 

This is an example of a general problem with CSS, which is that there is no way to compute the 'remaining space' in various layouts.

I've run into situations where you (a) need an exact layout, and (b) where you don't know the size of the floating item.

Example:

[---- input field that takes 100% of the remaining space ----] [button of unknown width]

You would think that this was possible, but AFAIK, you have to use tables to achieve this. There isn't even a proposal in CSS for how this would be fixed in the future. sigh

sho