C# asp.net,面板宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/606546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
asp.net, Panel Width
提问by Kartik
I am using .net 2005. In that i have master page and content page, i am using panel inside content.
我正在使用 .net 2005。因为我有母版页和内容页,我在内容中使用面板。
Is any body know how to set panel width as per screen size at run time ??
有没有人知道如何在运行时根据屏幕尺寸设置面板宽度?
Thanks
谢谢
回答by Fabian Vilers
Add a javascript function on onload event on the body tag to resize your panel width.
在 body 标签上的 onload 事件上添加一个 javascript 函数来调整面板宽度。
Note, this code has been typed without syntax verification.
请注意,此代码是在没有语法验证的情况下键入的。
<script language="javascript" type="text/javascript">
function Resize(item, width)
{
document.getElementById(item).width = width;
}
</script>
<body onload="Resize(<%= Mypanel.ClientID %>, screen.width)">
回答by Nick Allen
Set a css class attribute on your panel
在面板上设置 css 类属性
<asp:Panel CssClass="fullWidth" ID="MyPanel" runat="server">
</asp:Panel>
Then link to an external css stylesheet from your master page an in that set the following
然后从您的母版页链接到外部 css 样式表,并在其中设置以下内容
.fullWidth
{
width: 100%;
}
NOTE: This sets the width of any element with class fullWidth to 100% of the width of it's parent and can be used for other elements also
注意:这会将 fullWidth 类的任何元素的宽度设置为其父元素宽度的 100%,也可用于其他元素