使用CSS更改HTML按钮字体

时间:2018-06-09 11:06:52

标签: html css button

我一直在尝试并且无法使用CSS更改按钮字体。我可以改变他们的背景颜色,我可以更改textarea输入的字体,但由于某种原因,我似乎无法更改按钮的字体。根据我的有限理解,以下代码应该有效:

<html> 
<head> 
<style> 
    body {
        font-family: monospace;
    }
    input[type=button] {
        font-family: monospace;
    }
    </style> 
</head>
<body> 
    This is a button: 
    <input type = "button" value = "Please click"> 
</body> 
</html> 

但只更改文本的字体,而不是按钮。我错过了什么?

[更新]根据此处的回复,我将input [type = button]更改为input[type=button]

3 个答案:

答案 0 :(得分:4)

这很简单,你已经拥有它了。我认为你在编写它的CSS时犯了一个错误,你在input[type=button]中有一个空格,虽然你非常接近。

<style> 
body {
    font-family: monospace;
}
input[type=button] {
    font-family: monospace;

}
</style>

答案 1 :(得分:2)

您在input[type=button]之间有一个间距。删除它,它会工作。试试这段代码。

 input[type=button] {
        font-family: monospace;
    }

答案 2 :(得分:1)

问题是输入后的空间。这应该有效:

<html> 
<head> 
<style> 
    body {
        font-family: monospace;
    }
    input[type = button] {
        font-family: monospace;
    }
    </style> 
</head>
<body> 
    This is a button: 
    <input type = "button" class = "button" value = "Please click"> 
</body> 
</html>