【问题标题】:html button styleshtml按钮样式
【发布时间】:2011-09-04 03:05:19
【问题描述】:

如何在一个按钮上添加多种样式...这行不通。

<button style="background:red", "cursor:pointer">click me</button>

我试过了:

  • style="background:red", "cursor:pointer"
  • style="background:red" "cursor:pointer"
  • style="background:red" style="cursor:pointer"

是否可以组合多种样式?

【问题讨论】:

  • 你应该看看如何正确声明内联样式...看看这个:is.gd/jUKeOY
  • @Dan 或如何正确避免它们...
  • @AlienWebguy - 是的,那也是......
  • 避开style 属性是一种方法,而不是规则(例如,此页面的源有多个style 属性)。问题的答案是如何格式化属性,而不是如何完全避免 style 属性(这是一种观点)。

标签: html button


【解决方案1】:

您应该真正使用 css 类并避免内联样式化 DOM 节点:

<style type="text/css">
    .btn {
        background-color:red;
        cursor:pointer;
    }
</style>

<button class="btn">Click me</button>

更理想的是,您应该创建一个 CSS 文件。

CSS(样式.css):

.btn {
    background-color:red;
    cursor:pointer;
}

HTML:

   <link rel="stylesheet" href="style.css" />
   <button class="btn">Click me</button>

【讨论】:

    【解决方案2】:

    ; 分隔属性并将所有属性放在同一组引号之间:

    <button style="background:red; cursor:pointer">click me</button>
    

    http://jsfiddle.net/userdude/GcY97/

    CSS 类声明也是如此:

    button {
        background: red;
        cursor: pointer;
    }
    

    【讨论】:

      【解决方案3】:

      你用分号分隔所有 html 样式属性 - ;

      style="background: red; cursor: pointer;"
      

      【讨论】:

      • 您的代码也可以,但是类是一种更简洁的方式。我不知道你可以那样做。
      猜你喜欢
      • 2016-12-02
      • 2012-04-27
      • 2011-03-17
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多