【问题标题】:Gridview header align to left, does not work on IE9, but it works on chromeGridview 标题左对齐,不适用于 IE9,但适用于 chrome
【发布时间】:2013-07-14 17:02:00
【问题描述】:

我有一个网格视图,我想将其标题对齐到左侧。 它在 chrome 中工作,但在 IE 9 中它们不左对齐。

(我粘贴了整个代码,以防某些被包围的 div 负责此行为。)

        <div style="height: 300px; overflow: auto">
            <asp:GridView ID="myGrid" 
                AutoGenerateColumns="true"
                runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left"/>
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <So![enter image description here][1]rtedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>
        </div>
        <div style="margin-top: 20px; margin-left: 550px">
            <asp:Button ID="btnClose" runat="server" Text="Close" />
        </div>
        <div>
            <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
        </div>
    </div>

更新1:CSS

#DeltaPlaceHolderMain #ctl00_PlaceHolderMain_myGrid tr:first-child{
    background-color:#eb8c00 !important;
    color:#FFF !important;
    }
#DeltaPlaceHolderMain #ctl00_PlaceHolderMain_myGrid tr:first-child td{
    text-align:left;
    }

#DeltaPlaceHolderMain #ctl00_PlaceHolderMain_myGrid tr{
    color:#404041 !important;
    }

【问题讨论】:

    标签: html asp.net css gridview


    【解决方案1】:

    这行得通。将“CssClass”添加到您的 HeaderStyle:

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" CssClass="headerClass" />
    

    然后声明如下样式:

    /*Give a text-align left only to the gridview header th's*/
    .headerClass > th 
    {
        text-align:left;
    }
    

    为了进一步解释,HeaderStyle.CssClass 将为包含您的标题的&lt;tr&gt; 提供一个类。 CSS 选择器.headerClass &gt; th 将其样式应用到标题的所有子&lt;th&gt;,因此将左文本对齐应用到每个标题单元格。

    【讨论】:

      【解决方案2】:

      你不能放一下

      table th {text-align:left;}

      在你的 CSS 中?

      还是我错过了什么?

      【讨论】:

      • 如何在gridview、header style标签中做到这一点?
      • 我不希望有太多的子引用。这会让您失去概览,并且要求更高。 Fancy css article
      • 我刚刚添加了一些设计师放置的css类,也许有帮助?
      【解决方案3】:

      您不能在 tr 上左对齐。

      但是,tdth 会起作用。

      无论如何,我建议使用 css 类或 css 文件中的 th 来执行此操作。

      .myLeftAlign {
      text-align: left;
      }
      

      th {
      text-align: left;
      }
      

      如果您不想使用 css,请将 Align 属性放在您的 th 上,而不是您的 tr

      【讨论】:

      • 它是一个gridview,它会自动生成html元素,我需要在gridview标签headerstyle上设置它。/
      • 我刚刚添加了一些我找到的css类,设计师放的。
      猜你喜欢
      • 1970-01-01
      • 2013-02-19
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多