Effects of Clicking a Button

3

I'd like to know how I can add an effect when I click a button, I'm using HTML5 and CSS.

I add an effect with: HOVER, that as soon as the mouse is positioned over the button the background of the same is changed, but I would like an effect that click on the button the change effect in the color is enabled.

Thank you!

    
asked by anonymous 01.09.2016 / 05:37

1 answer

1

In this case you will have to use JavaScript. Try applying the following code.

<style>
    button{
        border: 0;
        padding: 35px 50px;
        font-weight: bolder;
        color: #fff;
    }
</style>
<script>

function mudaCor(el){
    el.style.backgroundColor = '#'+Math.floor(Math.random()*16777215).toString(16);
}

</script>


<button onclick="mudaCor(this)">Clique</button>

In case the JavaScript function is catching a random color, if you want a default color just change the hexadecimal code. See the example below

el.style.backgroundColor = '# 069';

    
01.09.2016 / 12:49