In web development, buttons are an indispensable element. Buttons can add interactivity to a website or application and improve user experience. The color of the button also has an important impact on the beauty of the overall interface and the user's operating experience. In this article, we will explain how to change the color of a button using CSS.
1. CSS Color
In CSS, color can be expressed in the following ways:
1. Hexadecimal color code: #RRGGBB, where RR, GG , BB represent the color codes of red, green and blue respectively. For example, #FF0000 represents red, #00FF00 represents green, #0000FF represents blue, #FFFFFF represents white, and #000000 represents black.
2.RGB format: rgb(R, G, B), where R, G, and B represent the color values of red, green, and blue respectively, ranging from 0-255. For example, rgb(255, 0, 0) represents red, rgb(0, 255, 0) represents green, and rgb(0, 0, 255) represents blue.
2. Change the color of the button
Changing the color of the button can be achieved in the following two ways:
1. Through CSS inline style
You can use the style attribute in HTML tags to define CSS styles, for example:
The above code sets the background color of the button to red.
2. Through the CSS style sheet
, you can define the CSS style in an external file and link the file to the HTML document. For example, create a style sheet file button.css with the following content:
.button{
background-color:#FF0000;
}
Reference the style sheet file in the HTML document and add the button The class attribute is set to button, for example: