2015-12-14 44 views
0

我遇到了在圖像上應用顏色疊加之後,內容(如按鈕)不再可點擊的問題。我已將範圍縮小到.overlay:之前的 CSS代碼。當我註釋掉這段代碼時,我可以再次點擊按鈕。但是,我無法弄清楚代碼中的確切原因。任何幫助將非常感激!覆蓋導致按鈕變得不可點擊

的jsfiddle:http://jsfiddle.net/suomyone/3ewzur9b/1/

這裏的HTML:

<section class="overlay blue2" id="contact" name="contact"> 
    <img src="http://placehold.it/300x200" /> 
    <h3>Contact</h3> 
    <p><b>T:</b> ###-###-####</p> 
    <p><b>F:</b> ###-###-####</p> 
    <button type="button" class="contactButton">Contact Us</button> 
</section> 

這裏的CSS:

.overlay { 
    position: relative; 
} 

.overlay:before { 
    position: absolute; 
    content: " "; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
} 

.blue2 { 
    background-color: rgba(36, 131, 178, 0.9); 
} 

#contact { 
    color: #fff; 
    width: 500px; 
    height: 300px; 
    padding: 1.875em 2.8125em 0 2.815em; 
    overflow: hidden; 
} 

#contact img { 
    width: 100%; 
    height: 100%; 
    top: 0; 
    left: 0; 
    position: absolute; 
    z-index: -1; 
} 

.contactButton { 
    color: #fff; 
    font-size: 0.864375em; 
    text-transform: uppercase; 
    width: 10.55676em; 
    height: 1.80766em; 
    margin-top: 10px; 
    background-color: #F7CB5F; 
    border: 1px solid #F7CB5F; 
    border-radius: 7px; 
    -moz-border-radius: 7px; 
    -webkit-border-radius: 7px; 
    cursor: pointer; 
} 

.contactButton:hover { 
    background-color: #2483B2; 
    border: 1px solid #2483B2; 
} 

.contactButton:active { 
    position: relative; 
    top: 1px; 
} 

回答

0

給這個按鈕之外,則默認值(靜態)的位置,並回應說:

.contactButton { 
    color: #fff; 
    font-size: 0.864375em; 
    text-transform: uppercase; 
    width: 10.55676em; 
    height: 1.80766em; 
    margin-top: 10px; 
    background-color: #F7CB5F; 
    border: 1px solid #F7CB5F; 
    border-radius: 7px; 
    -moz-border-radius: 7px; 
    -webkit-border-radius: 7px; 
    cursor: pointer; 
    position: relative; /* NEW */ 
} 

jsFiddle example

+0

完美地工作。謝謝。請介紹一下解決方案背後的邏輯是什麼?如何確定其相對解決問題的立場? – heyitsjhu

+0

給按鈕相對位置建立一個[堆棧上下文](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context)。 – j08691

+0

Gotcha。再次感謝! – heyitsjhu