Gridview CSS 边框不一致

发布于 2024-08-14 02:14:37 字数 1320 浏览 1 评论 0 原文

这真的很困扰我。我正在使用 GridView 并希望对其进行格式化,以便边框在所有浏览器中显示相同。目前,我在 IE、FF 和 Chrome 之间得到了不同的结果。我不确定我的 CSS 做错了什么(我对 CSS 还很陌生),但某些东西一定是正确的,因为其中一个浏览器随时都能正确显示边框。 gridview CSS 如下:

.gridViewData
{
    height:auto;
    width:544px;
    position:relative;

    text-align:center;

     background-color:#7D9EBA;
     border:solid thin black;
     border-right:none 0px black;



}

.gridViewData td 
{
    padding:2px;
    border-top-style:none;
    border-bottom-style:solid;
    border-left-style:solid;
    border-right-style:none;
    border-color:Black;
    border-width:thin;



}

.gridViewData th
{
    height:10px;
    width: 544px;
    position:relative;
    text-align:center;
    border-top-style:dashed;
    border-bottom-style:solid;
    border-left-style:solid;
    border-right-style:none;
    border-color:Black;
    border-width:thin;
    background-color:white;


}

.gridViewData .alt
{
     background-color:Red; 
}

.gridViewData .pgr 
{ 
    background-color:Orange; 
}

我希望表格看起来像绘图的粗略尝试:D。标题单元格之间不应有边框。

 ____________________________
|____________________________|
|___|__________|________|____|
|___|__________|________|____|
|___|__________|________|____|

在 IE 中,标题没有上边框。在 FF 中,它看起来不错,在 Chrome 中,标题中有分隔符。 这已经困扰我一段时间了,所以希望有人能对此有所启发。

谢谢

This is really bugging me. I'm using a GridView and want to format it in such a way that the borders are displayed the same in all browsers. At the moment, I'm getting varying results between IE, FF and Chrome. I'm not sure what I'm doing wrong in my CSS (I'm quite new to CSS) but something must be right as one of the browsers displays the borders correctly at any time.
The gridview CSS is as follows:

.gridViewData
{
    height:auto;
    width:544px;
    position:relative;

    text-align:center;

     background-color:#7D9EBA;
     border:solid thin black;
     border-right:none 0px black;



}

.gridViewData td 
{
    padding:2px;
    border-top-style:none;
    border-bottom-style:solid;
    border-left-style:solid;
    border-right-style:none;
    border-color:Black;
    border-width:thin;



}

.gridViewData th
{
    height:10px;
    width: 544px;
    position:relative;
    text-align:center;
    border-top-style:dashed;
    border-bottom-style:solid;
    border-left-style:solid;
    border-right-style:none;
    border-color:Black;
    border-width:thin;
    background-color:white;


}

.gridViewData .alt
{
     background-color:Red; 
}

.gridViewData .pgr 
{ 
    background-color:Orange; 
}

I'd like the table to look like this crude attempt at a drawing :D. The header should have no borders between the cells.

 ____________________________
|____________________________|
|___|__________|________|____|
|___|__________|________|____|
|___|__________|________|____|

In IE, the header has no top border. In FF, it looks fine an in Chrome there are separators in the header.
This has been bugging me for a while, so hopefully someone can shed some light on this.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2024-08-21 02:14:37

使用 GridView 属性来实现此目的,而不是将 CSS 应用于生成的表元素。例如,可以通过将 CSS 应用于属性来设置标题样式:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.headerstyle.aspx

编辑:

请注意,声明性 bordercolor 属性添加了一个内联样式声明,该声明仅适用于表格本身,不适用于单个单元格。以编程方式添加 bordercolor 属性不使用内联样式,而是使用 HTML bordercolor 属性,浏览器将其应用于表格内的所有边框:

OnRowDataBound="MyGrid_RowDataBound"

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
     foreach (TableCell tc in e.Row.Cells)
     {
         tc.Attributes["style"] = "border-color: #000";
     }
} 

我发表了一篇关于此的博客文章 - 检查 Lee Dumond 的评论:

http://www.codersbarn.com/post /2009/05/31/Set-Color-of-GridLines-in-Gridview.aspx#comment

Use the GridView properties to achieve this rather than applying CSS to the generated table elements. For example, the header can be styled by applying the CSS to the property:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.headerstyle.aspx

EDIT:

Note that the declarative bordercolor attribute adds an inline style declaration which only applies to the table itself, not individual cells. Adding the bordercolor attribute programmatically does not use an inline style, but uses the HTML bordercolor property, which browsers apply to ALL borders inside the table:

OnRowDataBound="MyGrid_RowDataBound"

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
     foreach (TableCell tc in e.Row.Cells)
     {
         tc.Attributes["style"] = "border-color: #000";
     }
} 

I put out a blog post about this - check Lee Dumond's comment:

http://www.codersbarn.com/post/2009/05/31/Set-Color-of-GridLines-in-Gridview.aspx#comment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文