简体   繁体   中英

How do I maintain two different alignments, one for each sub-element, in my ItemTemplate element?

I have a pretty straightforward ASP.NET website. I'm pulling all my data for the code from a database. I'm trying to figure out why when I change my text size, it takes effect, but if I change the text-align property, it doesn't take effect. Here's the code:

<asp:DataList ID="DataList1" DataSourceID="AccessDataSource2" 
    runat="server" ItemStyle-CssClass="picTableStyle"
    DataKeyField="ID">
    <ItemStyle CssClass="picTableStyle"></ItemStyle>
    <ItemTemplate> 
    <br /><br />
        <table>
        <tr>
        <td colspan="2">

        </td>
        </tr>
        <tr> 
        <td><asp:Image ID="Image1" runat="server" ImageUrl='<%# "PlaceImages/" +
                 Eval("Image") %>' /><br />
            <asp:Label ID="Label1" class="picCaptionStyle" runat="server" Text='<%# 
                 Eval("Caption") %>' /></td>

        <td>
            <asp:Label ID="Label2" class="picTitleStyle" runat="server" Text='<%# 
                 Eval("PicTitle") %>' /><br />
            <asp:Label ID="Label3" runat="server" Text='<%# Eval("TravelDate", 
                 "{0:MMMMMMMMM dd, yyyy}") %>' /><br /><br />
            <asp:Label ID="Label4" runat="server" Text='<%# Eval("PicText") %>' />
        </td>
        </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

Here is the pertinent section in my .css file:

    .picCaptionStyle
    {
        font-family:Century;
        text-align:center;
        font-size:8pt;
    }
    .picTitleStyle
    {
        font-family:Agency FB;
        text-align:left;
        font-size:14pt;
        color:Red;
        vertical-align:top;
    }
    .picTableStyle
    {
        vertical-align:middle;
    }

It only ever centers when I change the .picTableStyle rule to text-align:center; and leave it out on the other rules. But of course, it centers all the text in my ItemTemplate. I want to center the caption for the picture on the picture, but keep the text left.

take the labels into spans and provide style into span. Maybe this will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM