2

I have a panel in asp page and I want to add image to this panel so that this image is located at the center of the panel:

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);
}

I tried using CSS:

p.CssClass = "css1";

and css is:

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

but this didn't give result.

So, how to locate image in center of the panel (horizontally and vertically)?

Please, do not recommend

padding-top:20px; 

this changes the height of the panel. I must keep dimensions of panel constantly.

Nurlan
  • 2,860
  • 19
  • 47
  • 64

1 Answers1

4

A panel just renders as a div, so the answers to this question should be of use:

Align vertically using CSS 3 (The second answer in particular, by @j-man86, has detail on two ways of solving the problem).

If you just want vertical-align: middle; to work, then the easiest way is to add display: table-cell; to the same css declaration, but that's not necessarily the best CSS solution to vertical alignment.

Community
  • 1
  • 1
Jude Fisher
  • 11,138
  • 7
  • 48
  • 91