tags:

views:

97

answers:

4

I'm to implement a fullscreen layout for a Web app according to custom specs. I've got most of it under control but there's one part I have some trouble with.

To economize on space in an otherwise already crowded GUI, a "Log out" button should go into the title row rather than elsewhere. The title row, of course, contains a title. The button should appear in its default dimensions for the given browser/opsys combination at the top right, with a little padding. The title should be centered in the remaining space in that row. Here's a picture:

+====================+=======+
|    ACME Widgets    | [Btn] |
+====================+=======+

I don't know how wide the button will be, nor should I need to. The layout should scale smoothly on a range of devices and resolutions, from about 200 px width to 2000:

+==================================================+=======+
|                   ACME Widgets                   | [Btn] |
+==================================================+=======+

...with the title continuing to be centered in its area, which again will always be (total available width - width required for the button). The page may end up being used in a JavaScript-less environment, so dynamic size calculation is not an option. Nor (before you ask) is talking the customer out of his design.

Can anyone please suggest HTML (and, if required, CSS) to achieve this layout?

Update More constraints/explanation (sorry): This app could be viewed by people with poor vision, who like to use their zoom button (Ctrl-+) to blow up font sizes. Therefore, I'd like to go with as few assumptions about things like text sizes as possible. Obviously, on a tiny display with big zoom I would eventually not have enough space for the unpadded title and button; but until then I'd like to stay flexible.

+1  A: 

You can use a floating div.

<div style="float:right">[Btn]</div>
<h1 style="text-align:center;">ACME Widgets</h1>

Edit: second attempt, using a displayed-but-invisible div with the same button as content to center the title in the remaining space (aka doing math in css :)

<div style="float:right">[Btn]</div>
<h1 style="text-align:center;">ACME Widgets<div style="visibility:hidden">[Btn]</div></h1>
Adrian
This will work except the heading is not centered in the _remaining space_.
Chetan Sastry
@Chetan: Agree. If it were this easy I wouldn't need to ask SO.
Carl Smotricz
See edit above.
Adrian
Don't know yet if it will work as intended, but very original and clever! Will test tonight. +1.
Carl Smotricz
A: 

Might not be the most elegant solution but something like this should work. This is based off Adrian's solution

CSS

h1 {position: relative; left: 0; right: 100px; text-align: center}
.logout {float: right; width: 100px}

HTML

<div class="logout">Log me out</div>
<h1>ACME widgets</h1>
Chetan Sastry
Sorry, no. This assumes I know my button is 100px wide. If this is not the case I either waste space or create an ugly asymmetric layout.
Carl Smotricz
If you are floating something, you must specify a width. If your button is of variable width, you may want to look into tables.
Chetan Sastry
Indeed one of my options, +1. I'm still trawling for alternatives at this point, though.
Carl Smotricz
If `Ctrl +` zooming is your concern, the browser will scale up the widths correspondingly as well i.e. it is not going to be fixed at 100px at 200% zoom. Try it out.
Chetan Sastry
* sigh * It's *one* of my concerns, alas! But thanks for the tip, I'm looking forward to checking that particular detail out.
Carl Smotricz
Just wanted to add that there are actually two different ways that my Firefox will zoom when hitting `Ctrl +`, one will indeed zoom dimensions (and images and everything) so your comment about 100px scaling up is correct, but there is also "zoom text only" mode, which does not zoom images, dimensions, etc.. Only the text. (See View -> Zoom -> Zoom Text Only). I suppose this very much depends on the type and settings of the browser, then!
Funka
+1  A: 

If table is acceptaable use that

<table border="0" width="100%">
  <tr>
    <td align="center">ACME Widgets</td>
    <td width="60">button</td>
  </tr>
</table>
borayeris
Carl does not want to make assumptions about the width of the button.
Adrian
So far, table looks like the only solution that will just work. If I take the button cell's width down to 0 or 0%, it will be exclusively sized by its content. +1.
Carl Smotricz
+1  A: 

I have two possible solutions. I will admit, they seem like these are simply modifications to some answers already given but should hopefully address the comments you've left so far.

CSS approach:

Lets say you determine that a nice width for your button is 5em. This of course scales with the browser's text zoom to always be, well, 5em.

Then perhaps you could float this to the right, and put a margin-right on your title of 5em.

#buttonContainer {
 float:right;
 display:inline;
 width:5em;
 text-align:right;
}
#titleContainer {
 text-align:center;
 margin-right:5em;
 border:1px solid blue;
}

<div id="buttonContainer">
    <input id="btnLogOut" type="button" value="Log Out" />
</div>
<div id="titleContainer">
    <h1 style="text-align:center;" id="title">ACME Widgets</h1>
</div>

This approach may not be picture-perfect, but you can tweak the em unit and arrive at a nice solution hopefully.

Table-approach:

Another approach is a modification of the table-based approach given by borayeris. I have modified this to not make any assumptions about the width of the button...

<table border="0" width="100%">
  <tr>
    <td width="99%" align="center">ACME Widgets</td>
    <td width="1%" align="right">button</td>
  </tr>
</table>

Good luck!

Funka
Don't like the CSS because I'd be hard coding and fiddling with width units. The table approach looks workable. %s are OK and I think I can even go to 100/0. Thanks for all the work, +1.
Carl Smotricz
Most comprehensive and pragmatic answer, accepted with thanks.
Carl Smotricz