简体   繁体   English

CSS不适用于Gridview的div

[英]CSS is not applying to div with Gridview

I want to have a div with my Gridview in it but the CSS for my div is not working. 我想在其中包含Gridview的div,但是我的div的CSS无法正常工作。 Here is the code: 这是代码:

<div class="grid">
<asp:GridView ID="GridView1" runat="server" CssClass="grid" CellPadding="1">
</asp:GridView>
</div>

And my CSS is like: 我的CSS就像:

.grid{

float:right;
border:solid;
margin: 2px;
width:400px;
} 

And the generated HTML : 和生成的HTML:

<div class="grid">
<div>
<asp:GridView ID="GridView1" runat="server" CssClass="grid" CellPadding="1">
</asp:GridView>
</div>
</div>

Even The border is not displayed.I don't know where that other div comes from but when I apply the style on the second div in Firebug it works. 甚至没有显示边框。我不知道其他div的来源,但是当我在Firebug的第二个div上应用样式时,它就起作用了。

HI now used to border property as like this HI现在习惯像这样限制财产

.grid{
border:solid 2px red;
} 

or you can try to this way 或者你可以尝试这种方式

.grid{
border-style: solid;
}

The border CSS property is a shorthand property for setting the individual border property values in a single place in the style sheet. border CSS属性是一种简写属性,用于在样式表的单个位置设置各个border属性值。 border can be used to set the values for one or more of: border-width, border-style, border-color. border可以用于设置以下一项或多项的值:border-width,border-style,border-color。

More about click here 有关更多信息, 请点击这里

Border style here 这里的边框样式

Just correct your css like 像这样纠正你的CSS

CSS 的CSS

.grid { 
 float:right;
 border: 2px solid green;
 margin: 2px;
 width:400px;
}

As you are using ASP, you'll have to use a special syntax to apply the css. 使用ASP时,必须使用特殊的语法来应用CSS。

BorderWidth="1px" BackColor="#000000" 

See https://msdn.microsoft.com/en-us/library/aa479342.aspx for more. 有关更多信息,请参见https://msdn.microsoft.com/zh-cn/library/aa479342.aspx

.grid{
overflow:hidden;
float:right;
border:solid;
margin: 2px;
width:400px;
} 

I have added overflow:hidden which I believe should solve your problem. 我添加了溢出:隐藏,我相信它可以解决您的问题。

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

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