【问题标题】:how to group the components to a fixed position on the screen in asp.net?如何在asp.net中将组件分组到屏幕上的固定位置?
【发布时间】:2010-08-03 12:42:14
【问题描述】:

我正在 asp.net 中设计一个注册页面。我正在使用面板对组件(标签、ddl 和文本框)进行分组,但是在运行时组件的页面位置正在发生变化。如何将组件固定到特定位置?

感谢您的问候, 拉达

【问题讨论】:

  • 您需要为问题提供一个示例(HTML 和 CSS)。

标签: javascript asp.net html css


【解决方案1】:

您可以使用表格标签 例如

【讨论】:

    【解决方案2】:

    最好将页面中的所有控件添加到表格中并设置表格行列位置 例如:

    <table style="width: 100%;">
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    </td>
                    <td>
                        <asp:Panel ID="Panel1" runat="server">
                            <table>
                            <tr>
                            <td>
                                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
                            </td>
                            <td>
                                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            </td>
                            <td>
                                <asp:DropDownList ID="DropDownList1" runat="server">
                                </asp:DropDownList>
                            </td>
                            </tr>
                            </table>
                        </asp:Panel>
                    </td>
                </tr>
    
            </table>
    

    【讨论】:

    • 这不一定是“更好”。你可以创建很棒的、流畅的、少表格的 CSS 表单。在看到/知道问题之前,您无法提供问题的解决方案。
    【解决方案3】:

    我建议使用面板元素的 cssclass 属性。下面是一个荒谬的例子。 (它仍然证明了这个概念)
    <style type="text/css"> .pi { position:fixed;
    top:100px;
    left:100px;
    height:100px;
    background-color:Red;
    width:1000px;
    }
    </style>
    <asp:Panel ID="Panel2" CssClass="pi" runat="server">
    <asp:TextBox ID="t1" runat="server" />
    </asp:Panel>

    【讨论】:

      【解决方案4】:

      不要give up and use tables,对于静态定位的元素,我将简单地将绝对定位 CSS 应用于元素周围的 div 或元素本身:

      .staticPosition
      {
          position:absolute;
          top:20px;
          left:20px;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-26
        • 1970-01-01
        • 1970-01-01
        • 2016-10-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多