【问题标题】:How can I add some wiggle room (lower padding or margin) to my HTML button?如何为我的 HTML 按钮添加一些摆动空间(下边距或边距)?
【发布时间】:2015-06-12 09:16:06
【问题描述】:

我正在动态创建控件并将它们添加到 Web 部件。

当我这样做时:

this.Controls.Add(new LiteralControl("<br />"));
Button btnSave = new Button();
btnSave.Text = "Save";
btnSave.Click += new EventHandler(btnSave_Click);
this.Controls.Add(btnSave);
this.Controls.Add(new LiteralControl("<br />")); // <= this does nothing

...按钮位于 Web 部件的最底部:

(注意添加“br”会被忽略)

如果我添加这个:

btnSave.BorderWidth = 6;

...它确实在按钮周围提供了一个边框,但它与背景的颜色不同——它是黑色的,如您所见:

如何在按钮下方添加一些空间,而边框的颜色不是背景?

更新

我想尝试建议的 btnSave.Style.MarginBottom 代码,但是 Button 的 Style 属性没有“MarginBottom”子属性,如下所示:

更新 2

当我尝试 Mohammad 的最新建议时:

btnSave.BorderColor = this.BorderColor;

...我得到了,“类型 'System.Drawing.Color' 是在未引用的程序集中定义的。您必须添加对程序集 'System.Drawing... 的引用。”

所以我尝试了:

using System.Drawing;

...但尝试编译导致:“名称空间'System'中不存在类型或名称空间名称'Drawing'(您是否缺少程序集引用?)”

【问题讨论】:

    标签: html sharepoint-2010 web-parts htmlbutton webpartpage


    【解决方案1】:

    试试这个:

    btnSave.style.marginBottom = "10px";
    

    您可以将数字更改为任何看起来不错的数字!

    【讨论】:

    • 请看我的更新(Style 没有“MarginBottom”属性)。
    • 如果您使用的是 javascript,即使您在自动完成中看不到它,也应该这样做。也许你没有看到它,因为你输入了一个大写的“M”。检查:w3schools.com/jsref/dom_obj_style.asp。另外,.style 都是小写的。
    • 这是 C#,不是 jQuery。
    • 对不起,这绝对是我的责任。您可以尝试使用 style.BorderColor 属性将颜色设置为背景颜色吗?
    • 我认为您需要添加对 System.Drawing.dll 的引用(在解决方案资源管理器中 - 也称为项目文件 - 右键单击​​“引用”文件夹并找到 System.Drawing,应该在 .网络标签
    【解决方案2】:

    这是票(灵感来自代码 sn-p(使用“div”)here

    //this.Controls.Add(new LiteralControl("<br />")); // <= this does nothing
    HtmlGenericControl breakingSpace = new HtmlGenericControl("br");
    this.Controls.Add(breakingSpace);
    

    【讨论】:

      猜你喜欢
      • 2013-01-05
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 2011-10-28
      • 2020-10-18
      • 2019-05-13
      • 2018-04-01
      相关资源
      最近更新 更多