Topic: How to left-align text in a text_area?

Please have a look at this screenshot: http://www.ukautobarn.com/images/form_screenshot.tiff

How can I make the text aligned at the left side of the text_area just like in the text_fields??? It's just not working for me. Any ideas??

The code is fairly simple:

<table class="largeTable" cellspacing="0">
    <tr>
        <td class="label">Name:</td>
        <td><%= text_field("page", "name") %></td>
    </tr>
    <tr>
        <td class="label">Keywords:</td>
        <td><%= text_field("page", "keywords", 'class' => 'longer') %></td>
    </tr>
    <tr>
        <td class="label">Body Text:</td>
        <td><%= text_area("page", "body", 'class' => 'longer format') %></td>
    </tr>
    <tr>
        <td class="label"></td>
        <td><input type="submit" value=" <%= @button %> ">
    </tr>
</table>

Last edited by PixelLover (2006-08-17 10:11:25)

Re: How to left-align text in a text_area?

That's odd.  Either there are spaces in there, or it's a stylesheet thing.  Do you have the CSS file?

Re: How to left-align text in a text_area?

The text area is part of the "format" class. Does that class have "text-align: right" in your CSS file or anything?

Railscasts - Free Ruby on Rails Screencasts

Re: How to left-align text in a text_area?

Here's the CSS. It's fairly simple. I've already played around with the "format" class for nearly an hour. I've also tried the "whitespace" property, but no success. And yes, there is plenty of whitespace in the source (the content is pulled from a database), but outside "text_area" tags, everything is neatly aligned on the left (e.g. in "text_field" tags).

.largeTable {
    width: 910px;
}

.largeTable td {
    max-width: 95px;
}

.largeTable .imageCell {
    width: 150px;
    max-width: 150px;
    padding: 0;
}

.largeTable .label {
    width: 20%;
}

.largeTable .longer {
    width: 100%;
}

.largeTable .format {
    font-size: 70%;
    text-align: left;
}

Re: How to left-align text in a text_area?

Hmm, it might have to do with the 100% width in .longer class. Do you still get the problem if you remove the classes?

<td><%= text_area("page", "body") %></td>

Railscasts - Free Ruby on Rails Screencasts

Re: How to left-align text in a text_area?

The answer is short: yes.

I've also posted on a number of CSS boards. Maybe this is not really a Rails issue...

Re: How to left-align text in a text_area?

It probably is a CSS issue, but if you removed the "class" attribute and you're still getting the problem I'm not sure what it is. Perhaps it is some CSS setting which is higher up and the text area is inheriting it.

Try removing all CSS from the document (or just turning CSS off in your browser). If the text is aligned correctly without CSS then try commenting out various parts of the CSS to determine what is causing the misalignment.

Railscasts - Free Ruby on Rails Screencasts