Button unavailable

We are currently using beautiful flat ccs buttons that show the push-down effect onclick. They have strange behavior:

.button {
    cursor: pointer;
    display: inline-block;
    color: #FFF;
    font-weight: normal;
    border-radius: 3px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    background: #32a2f0;
    border: 0px;
    border-bottom: 2px solid #1e87cc;
    padding: 10px 30px;
}
.button:hover {
    background: #1e87cc !important;
    border-bottom: 2px solid #0169AD;
}
.button:active {
    border-bottom: 0px !important;
    border-top: 2px solid #0169AD;
    margin-top: 2px;
    padding-top: 10px;
    padding-bottom: 8px;
}

http://jsfiddle.net/6SeG8/

Problem: when the button is pressed at the top of 2 to 4 pixels, the click event does not fire. Css: the active state is triggered, but the button action is not executed.

+3
source share
5 answers

Consider using a pseudo-element after:

.button:active:after{
  content: " ";
  position: absolute;
  top: -4px;
  left: 0;
  width: 100%;
  height: 100%;
}

Jsfiddle

Please note that it does not work in IE7 before.

+1
source

- , . , border-top: 0px; .., . , :

.button {
    ...
    border-top: 2px solid transparent;
}

.button:active {
    ...
    border-bottom: 2px solid transparent;
    border-top: 4px solid #0169AD; /* Added 2px to this, instead of 2px margin */
}

JSFiddle.

!important.

+3
.button:active {
    border-bottom: 0px !important;
    border-top: 2px solid #0169AD;
    //margin-top:2px;  //this is the problem
    padding-top: 10px;
    padding-bottom: 8px;
}

.button:hover {
    background: #1e87cc !important;
    border-bottom: 2px solid #0169AD; // This may cause the onclick not to work when clicking form the bottom of the button
}
+2

, ,

<a href="#" onclick="alert('button is clicked')"><span class="button">Click me</span></a>
0

.

, , ( ).

, "mouseup" 'click' . , javascript click .

, .

0

All Articles