Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 21st, 2005, 12:57 AM
Alec S.
Guest
 
Posts: n/a
Default ? Using EMs for positioning

Hi,

Can EMs be used for positioning? For example:

#navbar {
left: 2em;
top : 1.3em;
}


Does this allow for accurate positioning? Can I align elements properly
like this?


Thanks

--
Alec S.
alec <@> synetech <.> cjb <.> net



  #2  
Old July 21st, 2005, 12:57 AM
Steve Pugh
Guest
 
Posts: n/a
Default Re: ? Using EMs for positioning

On Wed, 6 Oct 2004 23:01:00 -0400, "Alec S." <a@a.com> wrote:
[color=blue]
> Can EMs be used for positioning? For example:[/color]

Yes.
[color=blue]
>#navbar {
> left: 2em;
> top : 1.3em;
>}[/color]

With no position property those will likely be ignored.
[color=blue]
> Does this allow for accurate positioning? Can I align elements properly
>like this?[/color]

Depends on the situation.

Steve

  #3  
Old July 21st, 2005, 12:57 AM
Eric Jarvis
Guest
 
Posts: n/a
Default Re: ? Using EMs for positioning

Alec S. a@a.com wrote:[color=blue]
> Hi,
>
> Can EMs be used for positioning? For example:
>
> #navbar {
> left: 2em;
> top : 1.3em;
> }
>[/color]

It can. Use em units when you want to relate the size or position of a
design element to the default text size. That's what the units are for and
that's what they do.
[color=blue]
>
> Does this allow for accurate positioning? Can I align elements properly
> like this?
>[/color]

No and yes. If the element needs to be aligned in any way that is
dependent on default font size it's the only way you can align it
properly. It will be accurately positioned if you are thinking in terms of
how it relates to font size, which is often ideal. It will not be
accurately positioned in terms of overall page size, if that's what you
need then % is the unit to use. Only you can tell which is the priority.
Both work well, neither does both accurately and properly unless you are
very clear about your design intentions.

For a "navigation bar" I will usually use em units to size it and position
it.

--
eric
www.ericjarvis.co.uk
"live fast, die only if strictly necessary"
  #4  
Old July 21st, 2005, 12:57 AM
Alec S.
Guest
 
Posts: n/a
Default Re: ? Using EMs for positioning

> "Eric Jarvis" <web@ericjarvis.co.uk> wrote in message
news:MPG.1bcf3ec68a4956c298d595@news.individual.ne t...[color=blue]
> "Steve Pugh" <steve@pugh.net> wrote in message[/color]
news:hip9m0lr77ofrkldoiuuh02qeh82dv77u0@4ax.com...



My page has a header, a contents bar to the left, a main area beside it,
and a footer. I use PX right now (header height is 60px, footer height is
15px, and contents width is 175px). I want to modify my page so that it can
be scaled to any resolution properly. I assume using EMs is the way to do
this. Is there some sort of tutorial available on converting an existing
static page to a scalable page?



--
Alec S.
alec <@> synetech <.> cjb <.> net



  #5  
Old July 21st, 2005, 12:57 AM
Neal
Guest
 
Posts: n/a
Default Re: ? Using EMs for positioning

On Thu, 7 Oct 2004 21:49:25 -0400, Alec S. <a@a.com> wrote:
[color=blue][color=green]
>> "Eric Jarvis" <web@ericjarvis.co.uk> wrote in message[/color]
> news:MPG.1bcf3ec68a4956c298d595@news.individual.ne t...[color=green]
>> "Steve Pugh" <steve@pugh.net> wrote in message[/color]
> news:hip9m0lr77ofrkldoiuuh02qeh82dv77u0@4ax.com...[/color]

Be sure if you attribute, you quote, and vice versa!
[color=blue]
> My page has a header, a contents bar to the left, a main area beside
> it,
> and a footer. I use PX right now (header height is 60px, footer height
> is
> 15px, and contents width is 175px). I want to modify my page so that it
> can
> be scaled to any resolution properly. I assume using EMs is the way to
> do
> this. Is there some sort of tutorial available on converting an existing
> static page to a scalable page?[/color]

Well, look at it this way. For scalability, you have two choices: % or em.
Em is based on the size of text. % is based on the size of the containing
block.

The containing block is usually the viewport. If I assign a width of 50%
to a div directly inside the body tags, it'll take up 50% of the width of
the viewport.

Now let's say you have what you describe, a left bar, a header bar, a
content area, and a blurb below. One way to do this...

<div id="header">...</div>
<div id="content">...
<div id="menu">...</div>
</div>
<div id="foot">...</div>

Note the menu is within the content div, after the content!

CSS might be a little like this - note that I'm just throwing ideas out,
it's not complete:

#header {padding: 0.5em; border: 2px solid yellow;}
#content {margin-left: 15em; padding: 0 0.5em; position: relative;}
#menu {position: absolute; top: 0; left: -15em; width: 14em;}
#foot {padding: 0.5em; border: 2px solid yellow;}

Now here comes the positioning logic. When we position with absolute, we
are setting where it will be with respect to the containing block.
However, sonce your header might be 1, 2, 3 lines high there's no way to
know where to put it, is there? Well, here's the thing - when we set an
element as positioned relative or absolute (or fixed) that element is now
the containing block for whatever's inside it.

That's why I did position: relative; on #content without offsetting it -
it's now acting as the containing block, and we can now position according
to that.

Experiment with this. Refer to http://www.w3.org/TR/CSS21/propidx.html if
you need help with the CSS properties.
  #6  
Old July 21st, 2005, 12:58 AM
Alec S.
Guest
 
Posts: n/a
Default Re: ? Using EMs for positioning

> Be sure if you attribute, you quote, and vice versa!

I didn't want to post the same message as a reply to both messages, but
wanted to reply to both and acknowledge them both. Plus, [too many] people
still use 56K so every byte they have to download counts.

[color=blue]
> <div id="header">...</div>
> <div id="content">...
> <div id="menu">...</div>
> </div>
> <div id="foot">...</div>
>
> #header {padding: 0.5em; border: 2px solid yellow;}
> #content {margin-left: 15em; padding: 0 0.5em; position: relative;}
> #menu {position: absolute; top: 0; left: -15em; width: 14em;}
> #foot {padding: 0.5em; border: 2px solid yellow;}[/color]


This is good but I'm trying to simulate frames with CSS. I've already got
it working nicely with PX but I want it to be scalable. Your method is
scalable but the footer stays at the bottom of the content rather than at
the bottom of the screen.


--
Alec S.
alec <@> synetech <.> cjb <.> net



 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles