c# - 删除多余的行 ASP.Net

标签 c# css asp.net

大家 我的网页中有一些奇怪的东西,因为它会在每个 Controller 之后自动添加新行

    <asp:Label ID="ll" Class="question_bold" runat="server" Text="label 1" Visible="false"></asp:Label>
    <asp:RequiredFieldValidator runat="server" id="lln" controltovalidate="Textbox" errormessage="* Required" Font-Bold="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic" />
    <asp:TextBox ID="Textbox"  runat="server" Visible ="false" Width="350px" ></asp:TextBox>
    <asp:LinkButton ID="check" CssClass="myclass" visible="false" runat="server" OnClick="check_Click">Check</asp:LinkButton>

这是 CSS 代码:

a.myclass{ color: #FF0000; text-decoration: none; }
a.myclass:hover { text-decoration: none; }

.question_bold {
    font-weight: bold;
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    background-color: #e6e6e6;
    height: 25px;
    width: 100%;
    display: block;
}

我试过更改显示,甚至从 asp 中删除整个 CSS,但仍然相同 我需要文本框、字段验证器、链接按钮在同一行上.... 有什么想法吗?!

enter image description here

最佳答案

下面的代码会将控件排成一行。它使用 CSS3 flexbox 来排列控件。

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
         <style>
             a.myclass{ color: #FF0000; text-decoration: none; }
            a.myclass:hover { text-decoration: none; }

            .question_bold {
                font-weight: bold;
                border: 1px solid #e6e6e6;
                border-radius: 10px;
                background-color: #e6e6e6;
                height: 25px;
                width: 100%;
                display: block;
            }

            .flex-container {
                display: flex;
                width: 650px;
                height: 250px;
            }

            .flex-item {
                height: 100px;
                margin: 10px;
            }
         </style>
    </head>
    <body>
        <form id="form1" runat="server">

        <div class="flex-container">
            <div class="flex-item"><asp:Label ID="ll" Class="question_bold" runat="server" Text="label 1"></asp:Label></div>
            <div class="flex-item"><asp:RequiredFieldValidator runat="server" id="lln" controltovalidate="Textbox" errormessage="* Required" Font-Bold="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic" /></div>
            <div class="flex-item"><asp:TextBox ID="Textbox"  runat="server"  Width="350px" ></asp:TextBox></div> 
            <div class="flex-item"><asp:LinkButton ID="check" CssClass="myclass"  runat="server" OnClick="check_Click">Check</asp:LinkButton></div> 
        </div>
        </form>
    </body>
    </html>

上述解决方案需要浏览器支持CSS3 flexbox。你能设置每个控件的宽度吗?这也可以使用 CSS 来完成。下面的解决方案适用于不同的浏览器。

        <div>
            <span><asp:Label ID="ll" Class="question_bold" runat="server" Text="label 1" Width="100px"></asp:Label></span>
            <span><asp:RequiredFieldValidator runat="server" id="lln" controltovalidate="Textbox" errormessage="* Required" Font-Bold="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic" /></span>
            <span><asp:TextBox ID="Textbox"  runat="server"  Width="350px" ></asp:TextBox></span> 
            <span><asp:LinkButton ID="check" CssClass="myclass"  runat="server">Check</asp:LinkButton></span> 
        </div> 

关于c# - 删除多余的行 ASP.Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42190159/

相关文章:

c# - 如何使用 2 个或更多模型?

C# 位图不按原样保存

CSS3 渐变作为 SVG

asp.net - .ascx 中的条件 javascript

javascript - ASP.NET MVC 中的自定义输入格式

c# - 为什么我无法将此泛型类型的实例添加到集合中?

jquery - 显示我之前用 jQuery 隐藏的导航; jQuery 版本?

CSS - 在剪辑路径多边形上添加边框颜色

asp.net - 字 rune 字中的字符太多?

javascript - 如何防止下拉列表在 DropDownList 中打开?