【问题标题】:How to set style when BeginForm html helper is created?创建 BeginForm html 助手时如何设置样式?
【发布时间】:2017-02-21 03:03:36
【问题描述】:

我在我的 mvc5 项目中使用 Html.BeginForm() html helper。

我需要创建元素并设置style = "pedding:12px!important"

我在网上看到很多例子,但都是使用类,我不想声明类我只需要按原样放置样式。

我该如何实现它?

【问题讨论】:

  • 我想你想要padding,而不是pedding

标签: asp.net-mvc


【解决方案1】:

你需要this overload

Html.BeginForm("MyAction", "MyController", FormMethod.Post, new { style = "padding:12px" })

如果规则是在元素本身上定义的,不确定为什么要在 CSS 中添加 !important。这不会覆盖任何 CSS 吗?

!important 的使用应保留用于覆盖您无法修改的库中的其他“!important”规则。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 2014-11-24
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    相关资源
    最近更新 更多