Philip Rhoades
2006-Jan-06 08:52 UTC
[Rails] 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:
<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 Rhoades
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: phil@pricom.com.au
Kevin Olbrich
2006-Jan-06 12:39 UTC
[Rails] Re: Using DIV tags in HTML - a better Ruby/Rails way?
Philip Rhoades 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 -- Posted via http://www.ruby-forum.com/.
Alain Ravet
2006-Jan-06 12:47 UTC
[Rails] Re: Using DIV tags in HTML - a better Ruby/Rails way?
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
--
Posted via http://www.ruby-forum.com/.
Justin Forder
2006-Jan-06 18:24 UTC
[Rails] Using DIV tags in HTML - a better Ruby/Rails way?
Philip Rhoades wrote:> 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?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