Home > Web Front-end > CSS Tutorial > Example analysis of how to make button buttons change color using css

Example analysis of how to make button buttons change color using css

黄舟
Release: 2017-07-22 14:30:23
Original
3582 people have browsed it

First, let’s take a look at the final rendering:

This is our best goal. If you are interested, fine, then keep reading.

First of all, this button uses the new style attributes of css3.0. If your browser does not see the corner arc style, it means that your browser version does not support the new style of CSS3.0. The solution is to upgrade your browser to the latest one. As far as I know, XP and Windows Server 2003 support up to IE8 (you can see the effect). If you don’t want to upgrade IE, you have to download a browser that is not IE-based, such as Firefox, Google, Opera, etc.

Okay with all the nonsense ahead, let’s take a look at how to make our beautiful buttons.

In fact, we use the CSS pseudo-element here, hover.

First we must put an input type button on the page. Add css style to this button button.

The specific css code is as follows:

.mybtn {
    width:86px;
    text-align:center;
    line-height:100%;
    padding-top:0.5em;
    padding-right:2em;
    padding-bottom:0.55em;
    padding-left:2em;
    font-family:Arial,sans-serif;
    font-size:14px;
    font-style:normal;
    font-variant:normal;
    font-weight:normal;
    text-decoration:none;
    margin-top:0px;
    margin-right:2px;
    margin-bottom:0px;
    margin-left:2px;
    vertical-align:text-bottom;
    display:inline-block;
    cursor:pointer;
    zoom:1;
    outline-width:medium;
    outline-color:invert;
    font-size-adjust:none;
    font-stretch:normal;
    border-top-left-radius:0.5em;
    border-top-right-radius:0.5em;
    border-bottom-left-radius:0.5em;
    border-bottom-right-radius:0.5em;
    box-shadow:0px 1px 2px rgba(0,0,0,0.2);
    text-shadow:0px 1px 1px rgba(0,0,0,0.3);
    color:#fefee9;
    border-top-color:#da7c0c;
    border-right-color:#da7c0c;
    border-bottom-color:#da7c0c;
    border-left-color:#da7c0c;
    border-top-width:1px;
    border-right-width:1px;
    border-bottom-width:1px;
    border-left-width:1px;
    border-top-style:solid;
    border-right-style:solid;
    border-bottom-style:solid;
    border-left-style:solid;
    background-image:none;
    background-attachment:scroll;
    background-repeat:repeat;
    background-position-x:0%;
    background-position-y:0%;
    background-size:auto;
    background-origin:padding-box;
    background-clip:padding-box;
    background-color:#f78d1d;
}
Copy after login

For specific css style explanation, please go to Baidu, which can improve your css level. If you don't know CSS skills but want to use this effect, what you need to modify is the width of the button and set it to the appropriate width of your button. Another thing is to replace the background color.

After writing the css style and the input button button, we should associate them. We only need to add the class to the input button.

<input type="button" class="mybtn" value="我是按钮" />
Copy after login

Now we have the last step, which is to use the pseudo-element hover of css,

to write a mybtn hover style. The code is as follows:

.mybtn:hover {
    background: #f47c20;
}
Copy after login

Because we only need to modify the background color when we move the mouse up, we only need to modify one attribute in the hover style.

The above is the detailed content of Example analysis of how to make button buttons change color using css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template