Html html按钮样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7297174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:26:57  来源:igfitidea点击:

html button styles

htmlbutton

提问by Ricco

How can you add multiple styles to the one button...this doesn't work.

你怎么能在一个按钮上添加多种样式......这不起作用。

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

I have tried:

我试过了:

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

is it possible to combine multiple styles?

是否可以组合多种风格?

回答by AlienWebguy

You should really use a css class and avoid styling DOM nodes inline:

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

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

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

Even more ideally you'd create a CSS file.

更理想的情况是您创建一个 CSS 文件。

CSS (style.css) :

CSS (style.css) :

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

HTML :

HTML :

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

回答by Jared Farrish

Separate properties with ;and put all properties between the same set of quotes:

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

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

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

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

The same goes for CSS class declarations:

CSS 类声明也是如此:

button {
    background: red;
    cursor: pointer;
}

回答by Matt

You separate all html style properties with a semicolon - ;

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

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