How to center an image presented as an ASP.NET control?

The question is pretty simple. I have <asp:Image>one who lives in <asp:Panel>. My goal is to provide a very simple “preview” where alignment to the left, center, or right is selected. The panel is the entire printable area (a sheet of paper 8.5 x 11 inches), and the image inside is the area that will actually be printed. Full code:

<asp:Panel ID="Panel2" runat="server"
    BackColor="Black"
    BorderStyle="Inset" 
    Width="425px"
    Height="550px" >
    <asp:Image runat="server" Height="425px" ImageAlign="" />
</asp:Panel>

I set the property ImageUrlin the code behind, no problem. If I want to align the entire image to the left or right, I can just point ImageAlign="[Left|Right]". However, I could not find a way to center the image in the panel. I tried all the different ImageAlign values, and none of them seem to do what I want. Am I here SOL? If I need, I can change the CSS class for the image or panel, but I could not understand anything successful with this approach.

+3
source share
4 answers

what if you use the HorizontalAlign = "Center" panel property .......

<asp:Panel runat="server" ID="Panel2" HorizontalAlign="Center">
</asp:Panel>
+5
source

( - div) :

CssStyle="text-align:center;"

.

, CssStyle ? - , .

+1

CSS panel properties:

CssStyle="alignCenter"

CSS

.alignCenter
{
    margin: 0 auto;
}
0
source

you can use the built-in stylesheet or an external stylesheet to do this and add your css code to it

0
source

Source: https://habr.com/ru/post/1714525/


All Articles