获取控件的宽度 ASP.NET
在asp.net中,如何根据控件的百分比获取控件的高度?
我可以获得宽度属性,但我将其设置为 100%,并且我需要
我需要的实际像素,以便我可以根据计算机的结果自定义我的网站。 (它可以是任何控制 - 面板、div 等)
In asp.net, how do I get a control's height according to its percentage?
I can get the width property but I set it to 100% and I need the actual pixels
I need it so I can customize my website according to the computer's resulotion. (It can be any control - panel,div, etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需访问(开箱即用的)控件的高度属性(以像素为单位)。计算该宽度除以页面中容器的宽度的比率,并将该数字表示为百分比。
例如:
(myControl.height/myPanel.height)/100 + "%";
但是,这并不是设计在不同大小的浏览器中都能正常运行的网页的方法。根据您使用的控件类型,这可能会变得非常混乱,我在这里只是谈论外观。为此和您的容器使用固定宽度。如果需要,可以使用 CSS 和 JS 逐步增强您的网站。
冒着被批评的风险,我要说的是:永远不要使用液体布局 - 它们会改变布局的比例并破坏页面的组成。使用液体布局最终总是导致您必须应用代码来更改图像相对于其容器的图像/高度比 - 这总是会导致图像质量损失和/或页面构图不良。
Just access the (out of the box) control's height property in pixels. Calculate the ratio of this width divided by width of its container in the page and express this number as a percentage.
For example:
(myControl.height/myPanel.height)/100 + "%";
However, this is not the way to design a Web page to play nice in different sized browsers. Depending on what type of control you're using, this could get real messy and I'm just talking appearance here. Use fixed width for this and your container. Progressively enhance your site with CSS and JS if you need to.
At the risk of getting roasted, I'm going to say this: NEVER used liquid layouts - they change the ratio of the layout and destroy the page composition. Using liquid layouts always ends up with you having to apply code to change the image/height ratio of your images in relation to their container - and this always results in loss of image quality and/or bad page composition.
我相信这在服务器端是不可能的,因为:
百分比被重定向到浏览器渲染引擎,我怀疑标准 ASP.NET 控件是否会对特定值执行任何操作。
I believe this is not possible on server side because:
The percentages are redirected to browsers rendering engine, I doubt standard ASP.NET controls do anything at all with the specific values.