a) 据我所知,GridView’s RowStyle-HorizontalAlign
属性应该覆盖 CSS 的 text-align
属性,因此 GridView 的单元格内的文本应该位于单元格的左侧,而是移动到右侧。这是为什么?
b) 同样,RowStyle-Font-Bold
应该覆盖 CSS 的 font-weight
属性,因此字体不应该是粗体。但同样,CSS 的属性会覆盖 RowStyle’s Font-Bold
属性(property)。为什么?
<div id="someClass">
<asp:GridView ID="gvwShowUsers" runat="server" >
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" Font-Bold="false"
HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
</Columns>
</asp:GridView>
</div>
CSS 文件:
#someClass td
{
font-weight:bolder;
text-align:right;
}
谢谢
编辑:
A workaround would be to apply the style to each field instead (e.g. ItemStyle-HorizontalAlign)
我尝试申请 ItemStyle
至 GridView’s
领域:
<div id="someClass">
<asp:GridView ID="gvwShowUsers" runat="server" >
<RowStyle Font-Bold="false" HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="UserName" HeaderText="UserName">
<ItemStyle HorizontalAlign="Left" Font-Bold="false" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
但自从申请了ItemStyle
该页面仍然在单元格的右侧显示文本,我决定检查发送给用户的 html 页面的源代码,结果是 <tr>
和 <td>
元素有Align
属性设置为 left
,所以……完全糊涂了!
这是一个html页面的源代码:
<table id="GridView1" style="font-weight:normal;">
<tr align="center" style=" font-weight:bold;">
<th scope="col">UserName</th>
</tr>
<tr align="right" valign="bottom" style="font-weight:normal;">
<td align="right" style="font-weight:normal;"> Nancy</td>
</tr>
</table>
最佳答案
如果样式被添加到 <tr>
元素,CSS 文件中的样式将获胜,因为 #someClass td
选择器更具体。
解决方法是将样式应用于每个字段(例如 ItemStyle-HorizontalAlign
)。
关于.net - GridView 的 RowStyle-HorizontalAlign 属性不应该覆盖 CSS 的文本对齐属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2480090/