HTML按钮样式

Ric*_*cco 4 html button

如何在一个按钮上添加多个样式...这不起作用.

<button style="background:red", "cursor:pointer">click me</button>
Run Code Online (Sandbox Code Playgroud)

我试过了:

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

是否可以组合多种风格?

Ali*_*guy 8

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

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

<button class="btn">Click me</button>
Run Code Online (Sandbox Code Playgroud)

更理想的是,您将创建一个CSS文件.

CSS(style.css):

.btn {
    background-color:red;
    cursor:pointer;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

   <link rel="stylesheet" href="style.css" />
   <button class="btn">Click me</button>
Run Code Online (Sandbox Code Playgroud)


Jar*_*ish 5

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

<button style="background:red; cursor:pointer">click me</button>
Run Code Online (Sandbox Code Playgroud)

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

CSS类声明也是如此:

button {
    background: red;
    cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)