c# - 垂直对齐asp面板

标签 c# asp.net panel vertical-alignment

我在asp页面中有一个面板,我想向该面板添加图像,以便该图像位于面板的中心:

protected void Page_Load(object sender, EventArgs e)
{
    Panel panel = new Panel();
    panel.HorizontalAlign = HorizontalAlign.Center;  
    //here I want set verticalAlign for the panel

    Image image = new Image();
    image.imageURL = imageurl;
    panel.controls.add(image);
    this.form1.controls.add(panel);
}

我尝试使用 CSS:

p.CssClass = "css1";

CSS 是:

<style type="text/css"> 
        .css1
        {
            vertical-align: middle;              
        }
</style>

但这没有给出结果。

那么,如何将图像定位在面板的中心(水平和垂直)?

请不要推荐

padding-top:20px; 

这会改变面板的高度。我必须始终保持面板的尺寸。

最佳答案

面板仅呈现为 div,因此这个问题的答案应该有用:

Align vertically using CSS 3 (特别是@j-man86 的第二个答案,详细介绍了解决问题的两种方法)。

如果你只是想让 vertical-align: middle; 工作,那么最简单的方法是将 display: table-cell; 添加到相同的 css 声明中,但是这不一定是垂直对齐的最佳 CSS 解决方案。

关于c# - 垂直对齐asp面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12743655/

相关文章:

c# - TemplateBinding 不适用于扩展 ComboBox 的自定义控件中的 SelectedItem

c# - 如何从 ViewModel 中的 ComboBox 中获取值

c# - Azure C# 函数 : How to read from Table Storage

components - Wicket 口 : Can a Panel or Component react on a form submit without any boilerplate code?

c# - 顶部的虚拟键盘

asp.net - Facebook C# SDK : "Invalid signed request" exception when parsing fbsr cookie

asp.net - 自动 IIS6 403.4 重定向到 SSL 不工作

asp.net - Redis 框架的服务堆栈许可证

在常见的谷歌服务中找到 GWT 可折叠面板?

C# 将 Control.Top 从 16 位更改为 32 位 Int (WinForms)