vb.net 在 ASP.NET 中为 Textbox 控件设置填充

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25801049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:11:32  来源:igfitidea点击:

Set padding for Textbox control in ASP.NET

asp.net.netvb.net

提问by user2948563

I needed to set the padding for text box controls in my ASP.NET web forms application because the were rendering inconsistently with Dropdownlist controls on the browser. The Dropdownlists had some padding between the text and the border and the Textboxes did not have any.

我需要在我的 ASP.NET Web 窗体应用程序中设置文本框控件的填充,因为它们与浏览器上的 Dropdownlist 控件呈现不一致。下拉列表在文本和边框之间有一些填充,而文本框没有。

Visual Studio does not provide a direct padding property for controls so trying to set/change padding for controls like Textboxes and Dropdownlists can be very frustrating. After a lot of searching without any getting any useful solutions i was able to do it. See Answer below.

Visual Studio 不为控件提供直接填充属性,因此尝试设置/更改文本框和下拉列表等控件的填充可能会非常令人沮丧。在没有得到任何有用的解决方案的情况下进行了大量搜索后,我能够做到这一点。请参阅下面的答案。

回答by a1771550

I strongly recommended you learn some CSS, so that you would not depend solely on the web controls provided by visual studio. As in your case, just put "cssclass='somestyle'" into your textbox control and that is:

我强烈建议你学习一些 CSS,这样你就不会仅仅依赖于 Visual Studio 提供的 Web 控件。与您的情况一样,只需将“cssclass='somestyle'”放入您的文本框控件中,即:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        .padding {
            padding:.5em;
        }
    </style>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="txtDemo" CssClass="padding"></asp:TextBox>
    </div>
    </form>
</body>
</html>

回答by user2948563

The answer lies in the CssClass Attribute of the control which go like Auto-Style1, Auto-Style2, etc.

答案在于控件的 CssClass 属性,例如 Auto-Style1、Auto-Style2 等。

If you have Dreamweaver installed you can open your .aspx web-form and select and edit the the CssClass Rules. (Select the Css tab on the properties tab below the page in Dreamweaver) Here you can set padding Rule (See 'Box option' in the Css Rule Definions - Uncheck 'Same for all' to set different Left, Top, Bottom, Right padding values) Save and the go back to Visual studio load the saved page and set that CssClass property of the control to the edited CssClass. (Do not set the CssClass for the control in Dreamweaver - you are likely to get errors when you run your application) I only edited the padding rule so i do not know the effect of editing other CssClass rules.

如果您安装了 Dreamweaver,则可以打开 .aspx 网络表单并选择并编辑 CssClass 规则。(在 Dreamweaver 页面下方的属性选项卡上选择 Css 选项卡)在这里您可以设置填充规则(请参阅 Css 规则定义中的“框选项” - 取消选中“全部相同”以设置不同的左、上、下、右填充values) 保存并返回 Visual Studio 加载保存的页面并将控件的 CssClass 属性设置为编辑的 CssClass。(不要在 Dreamweaver 中为控件设置 CssClass - 运行应用程序时可能会出错)我只编辑了填充规则,所以我不知道编辑其他 CssClass 规则的效果。

It Worked! I have 5px padding for my Textboxes and they are now consistent with Dropdownlist padding (Chrome browser). They look lovely!

有效!我的文本框有 5px 填充,它们现在与 Dropdownlist 填充(Chrome 浏览器)一致。他们看起来很可爱!

Hope this helps Someone.

希望这有助于某人。

Screen Shot Dreamweaver and Visual Studio

屏幕截图 Dreamweaver 和 Visual Studio