简体   繁体   English

如何在ItemTemplate元素中保持两种不同的对齐方式,每个子元素一种对齐方式?

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

I have a pretty straightforward ASP.NET website. 我有一个非常简单的ASP.NET网站。 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. 我试图弄清楚为什么当我更改文本大小时它会生效,但是如果我更改text-align属性,它就不会生效。 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: 这是我的.css文件中的相关部分:

    .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; 仅当我将.picTableStyle规则更改为text-align:center时,它才会居中。 and leave it out on the other rules. 并把它放在其他规则上。 But of course, it centers all the text in my ItemTemplate. 但是,当然,它将所有文本置于我的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 也许这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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