如何在面板中并排设置控件

时间:2018-05-02 15:02:01

标签: c# html css asp.net

我有这样的事情:

enter image description here

但我需要将控件设置为彼此相邻:

enter image description here

我的Panel.aspx

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" 
Runat="Server">
<asp:Panel ID="pnlProducts" runat="server"></asp:Panel>
<div style="clear: both"></div>
</asp:Content>

我的Panel.aspx.cs

    foreach (DataRow row in dt.Rows)
    {
        int id = row;

        byte[] bytes = (byte[])row["image"];
        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
        Panel productPanel = new Panel();
            ImageButton imageButton = new ImageButton
            {
               ImageUrl = "data:image/png;base64," + base64String,
               CssClass = "productImage",
               PostBackUrl = string.Format("Product1.aspx?id={0}", row)
            };
            Label lblName = new Label
            {
                Text = row["nazwa"].ToString(),
                CssClass = "productName"
            };
            Label lblPrice = new Label
           {
               Text = row["cena"].ToString() + " zl",
               CssClass = "productPrice"
            };

            productPanel.Controls.Add(imageButton);
            productPanel.Controls.Add(new Literal { Text = "<br/>" });
            productPanel.Controls.Add(lblName);
            productPanel.Controls.Add(new Literal { Text = "<br/>" });
            productPanel.Controls.Add(lblPrice);
            pnlProducts.Controls.Add(productPanel);
    }
}

我的css代码

/*Webshop */
   #ContentPlaceHolder1_pnlProducts div {
   float: left;
   width: 250px;
   height: 250px;
   text-align: center;
  }

.productName {
font-weight: bold;
font-size: 18px;

 }

    .productPrice {
    font-family: arial,helvetica,sans-serif;
    color: #FFB600;
    }

  .productImage {
    width: 150px;
    height: 150px;
    vertical-align: central;
    padding: 10px;
   -moz-border-radius: 50px;
   -webkit-border-radius: 50px;
   border-radius: 50px;
 }

我不知道我在哪里使用float:左边或类似于如何在面板中并排设置控件的东西。

1 个答案:

答案 0 :(得分:0)

你应该使用Flex-box非常容易

在你的父母身上:

display: flex;
flex-wrap: wrap;

对孩子说:

flex: 1 1 20%;