Using DIV tags in HTML - a better Ruby/Rails way?

People,

I can use a DIV tag for exact positioning of fields on a form:

Creating a DIV tag creates a layer.

The DIV tag contains a style attribute with positioning information. It
might also have border and size information, if appropriate.

Here is the basic DIV tag required for exact positioning:

And this works quite happily for my little Rails library DB but in the
edit.rhtml file I have to manually create these lines for each
field-name/field combination and adjust coordinates appropriately -
could this be done more automatically with ruby/rails? - or does an
equivalent method already exist?

Thanks,

Phil.

Philip R.

Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney NSW 2001
Australia
Mobile: +61:(0)411-185-652
Fax: +61:(0)2-8221-9599
E-mail: [email protected]

Philip R. wrote:

People,

I can use a DIV tag for exact positioning of fields on a form:

Creating a DIV tag creates a layer.

The DIV tag contains a style attribute with positioning information. It
might also have border and size information, if appropriate.

Here is the basic DIV tag required for exact positioning:

And this works quite happily for my little Rails library DB but in the
edit.rhtml file I have to manually create these lines for each
field-name/field combination and adjust coordinates appropriately -
could this be done more automatically with ruby/rails? - or does an
equivalent method already exist?

Thanks,

Phil.

You could wrap your contents using a content_tag call.

<%= content_tag(“div”,@content, {“style”=>“contentdiv”} ) %>

I would suggest moving your style info into your CSS as much as
possible.

_Kevin

Next to what Kevin said, I recommend you read the 2-part “Stylesheet
Sanity” article:

http://justinfrench.com/?id=141

It helped me trim down my humongous stylesheet, and it’s readable again.

Alain

Philip R. wrote:

style="
edit.rhtml file I have to manually create these lines for each
field-name/field combination and adjust coordinates appropriately -
could this be done more automatically with ruby/rails? - or does an
equivalent method already exist?

Why do you want to use independent absolute positioning of each field?
It’s not recommended! It means that you are making layout decisions that
the browser should be making for you - you should be defining the rules,
rather than giving the results of applying those rules based on certain
assumptions about font sizes and window size (both of which may vary
widely, as they are under users’ control).

As others have pointed out, it is better to put style information in a
linked external stylesheet, rather than in the HTML.

Here are some links showing how other people are using CSS for form
layout:

http://jeffhowden.com/code/css/forms/
http://www.picment.com/articles/css/funwithforms/

These are just from a little Google searching… other readers may be
able to give more informed recommendations.

regards

Justin