1

I've been trying and failing to change button font with CSS. I can change their background color and I can change a textarea input's font, but for some reason I don't seem to be able to change a button's font. From my limited understanding, the following code should work:

<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> 

But only changes the font of the text, not the button. What am I missing?

[UPDATE] Per the responses here I changed input [type = button] to input[type=button].

Itai Yasur
  • 99
  • 1
  • 3
  • 10
  • `input [type = button]` != `input[type = button]` – Gabriele Petrioli Jun 09 '18 at 11:11
  • Okay, so I removed the spaces. If I add a change such as color before the font change, it works, but if the only change is font-family it doesn't do anything. Could anyone enlighten me on way that is? – Itai Yasur Jun 09 '18 at 11:37
  • In your case only the space between `input` and `[` was important. And it works fine (see https://jsfiddle.net/vrpoL7bh/) – Gabriele Petrioli Jun 09 '18 at 11:41
  • Hmm, the fiddle example shows up correctly on my phone but in every browser on my computer the button text remains unchanged. – Itai Yasur Jun 09 '18 at 11:46
  • Yeah, I'm getting the same issue in the fiddle. If I change other elements, such as the background and text color, the font shows up correctly. If I only change the font, the browsers not displaying it correctly. Issue on my end? – Itai Yasur Jun 09 '18 at 11:50
  • Just add `appearance: none;` to the button's css. –  Jun 11 '21 at 10:31

3 Answers3

6

It is so simple, you already have it. I think you made a mistake while writing CSS of it, you have a space in input[type=button], though you were pretty close.

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

}
</style>
Sitecore Sam
  • 377
  • 2
  • 8
  • 14
2

You have a spce between input and [type=button]. Remove it and it would work. Try this code.

 input[type=button] {
        font-family: monospace;
    }
Aryan Twanju
  • 2,464
  • 1
  • 9
  • 12
1

The problem is the space after input. this should work:

<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>
MehdiB
  • 870
  • 12
  • 34