views:

62

answers:

3

I am creating an Index page in an MVC 1.0 application and want to right-align the text in one of the columns. I have tried to do this by creating an extra class in the td style and setting the "text-align: right" in this but this doesn't appear to be being applied to that element.

In my CSS file I have:

table td
{
padding: 5px;
border: solid 1px #e8eef4;
}

table td.numeric
{
text-align: right;
}

In my view I have:

<table>
    <tr>
        <th>Location</th>
        <th>Duration</th>
    </tr>

    <% foreach (var item in Model) { %>
        <tr>
            <td><%= Html.Encode(item.Location.Description) %></td>
            <td class="numeric"><%= Html.Encode(itemDuration) %> min</td>
        </tr>
    <% } %>
</table>

Why wouldn't the text-align style be being used?

A: 

Make sure you are importing the style sheet in your view.

Dan
Yes, the style sheet is being imported in the master page and other styles are being applied. This works as expected in Firefox, it's just in IE7 that I'm now having the problem.
Val M
A: 

That should do it. Check for other conflicting styles in your stylesheet. If you're using a CSS reset, it might be in that.

D_N
+1  A: 

It works for me. Are you sure you don't have another CSS property overriding this one?

Also, have you checked to make sure your table width is such that you can actually see that the second td is right aligned? My guess is that your table isn't expanding properly. Try changing it's tag to:

<table width="100%">
David Morton
I have now downloaded Firefox and it is being displayed correctly in Firefox so this appears to be an IE7 issue. I realise that browser incompatability issues are outside the scope of this original question so I'll park this issue until I can read up more about that.The setting the table width to 100% didn't make a difference. I don't think it is a size of the table issue because I can see the whole table and that column is definitely left-aligned.
Val M
Running this in Firefox with Firebug shows the style for that td as:table td.numeric { text-align:right; } table td { border:1px solid #E8EEF4; padding:5px; } So it is seeing the style as I'd expect it to but isn't applying it.
Val M