Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button is unclickable

Tags:

html

css

Currently we make use of nice flat ccs-only buttons that show a push-down effect onclick. They have a weird behaviour:

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

The problem is: When clicking the button at the top 2 to 4 pixels, the click event will not trigger. The css :active state does trigger, but the action of the button does not.

like image 305
Rvanlaak Avatar asked Sep 11 '25 04:09

Rvanlaak


2 Answers

It's because of the borders and the top margin you're applying. Rather than specifying border-top: 0px;, etc., you should instead give a transparent border. You can then give extra width to the top border to make up for the margin:

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

Also you really shouldn't need to use !important at all.

like image 196
James Donnelly Avatar answered Sep 12 '25 18:09

James Donnelly


Consider using an after pseudo-element:

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

JSFiddle

Note, that it doesn't work in IE7 and earlier.

like image 27
Ray Poward Avatar answered Sep 12 '25 18:09

Ray Poward