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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Philip R. (Guest)
on 2006-01-06 10:55
(Received via mailing list)
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:

<div
   style="
      top: 99;
      left: 99;
      position: absolute;
      z-index: 1;
      visibility: show;">
<!-- content will go here -->
</div>


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:  removed_email_address@domain.invalid
Kevin O. (Guest)
on 2006-01-06 14:39
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:
>
> <div
>    style="
>       top: 99;
>       left: 99;
>       position: absolute;
>       z-index: 1;
>       visibility: show;">
> <!-- content will go here -->
> </div>
>
>
> 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
Alain R. (Guest)
on 2006-01-06 14:47
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
Justin F. (Guest)
on 2006-01-06 20:27
(Received via mailing list)
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://www.themaninblue.com/writing/perspective/2004/03/24/
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
This topic is locked and can not be replied to.