【问题标题】:Change button style in MVC5 view在 MVC5 视图中更改按钮样式
【发布时间】:2014-04-29 10:33:28
【问题描述】:

我使用在 MVC5 中创建的以下视图代码,我想更改按钮样式 像论坛按钮一样(例如,在这个堆栈论坛中提问按钮,添加按钮框架颜色等),我应该怎么做? 目前它只是文本,当你用鼠标悬停它时,你会看到它下面的线......

<p>
    @Html.ActionLink("Create New Item", "Create")
</p>

【问题讨论】:

    标签: c# html css asp.net-mvc-5 asp.net-mvc-5.1


    【解决方案1】:

    您只需要 css 来设置按钮样式。

    <p>
        @Html.ActionLink("Create New Item", "Create", 
            null, htmlAttributes: new { @class = "mybtn"})
    </p>
    <style type="text/css">
        a.mybtn {
            background: #777;
            color: #fff;
            display: inline-block;
            padding: 6px 12px 6px 12px;
            text-decoration: none;
        }
    </style>
    

    【讨论】:

      【解决方案2】:

      使用重载

      @Html.ActionLink("linktext", "action", "controller", routeValues: new { }, htmlAttributes: new { @class="" })
      

      然后提供一个 css 类。

      【讨论】:

      • 感谢 Jasen 投了赞成票,但我是新手,请您提供 css 类的示例以及我应该如何创建它?
      • Win 的回答解决了这个问题。如果您想复制 SO 的按钮,只需使用浏览器的检查工具并检查应用于该按钮的类规则。
      【解决方案3】:

      使用这个:

      <button type="submit" class="btn btn-labeled btn-info" onclick="location.href='@Url.Action(" Details ", "Movies
      ",new { id = item.Id})'" data-toggle="modal tooltip" data-target="" title="Details">
      <span class="btn-label">
          <i class="glyphicon glyphicon-comment"></i>
      </span>
      Details
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-10
        • 2016-09-11
        • 1970-01-01
        • 2014-12-04
        • 2023-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多