2014-07-08 39 views
0

我把一個按鈕居中在我的頁面,但我已經爲html標籤寫入的CSS過濾器也適用於我的按鈕。我如何避免這種情況?CSS過濾器適用於我的網頁的所有元素

enter image description here

HTML

<body> 
    <div class="button"> 
     <a href="#">START EXPERIENCE</a> 
    </div> 
</body> 

CSS

html { 
    background: url(../img/cover2.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
    -webkit-filter: brightness(0.5); 
    filter: brightness(0.5); 
    // Browser Specific 
    -moz-filter: brightness(0.5); 
    -o-filter: brightness(0.5); 
    -ms-filter: brightness(0.5); 
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 
} 

.button { 
    position: absolute; 
    left: 40%; 
    top: 50%; 
    -webkit-filter: none; 
} 

.button a { 
    text-decoration: none; 
    border: 2px white solid; 
    color: white; 
    padding: 25px; 
    padding-left: 100px; 
    padding-right: 100px; 
    -webkit-border-radius: 10px; 
    -moz-border-radius: 10px; 
    border-radius: 0px; 
    text-transform: uppercase; 
    font-weight: bold; 
    font-size: 22px; 
} 

.button a:hover { 
    background: white; 
    color: black; 
    color: rgba(0, 0, 0, 0.5); 
} 
+1

不知道,如果你可以,看到這個http://stackoverflow.com/questions/22584671/make- a-parent-div-webkit-filter-not-affect-children – Key

+0

我建議寧願給一個過濾器p roperty到'html'元素創建一個容器div,然後給該div分配一個屬性。 –

+0

對於具有相同屬性的按鈕的任何父項,這仍然是個問題。 –

回答

1

我已經申請了技術下面是一個div,但它可以擴展到整個頁面。

Codepen Demo

HTML

<div class="wrapper"> 
    <img src="http://lorempixel.com/400/400/sports/1/" alt="" /> 
    <div class="button">Some Text</div> 
</div> 

CSS

* { 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    box-sizing: border-box; 
} 

.wrapper { 
    width:400px; 
    height:400px; 
    margin:25px auto; 
    position: relative; 
} 

.wrapper img { 
    position: absolute; 
    top:0; 
    left:0; 
    width:100%; 
    height:100%; 
    -webkit-filter: brightness(0.5); 
    // Browser Specific 
    -moz-filter: brightness(0.5); 
    -o-filter: brightness(0.5); 
    -ms-filter: brightness(0.5); 
    filter: brightness(0.5); 
} 

.button { 
    position: absolute; 
    top:50%; 
    left:50%; 
    -wekbit-transform:translate(-50%,-50%); 
    transform:translate(-50%,-50%); 
    color:black; 
    font-weight: bold; 
    border:1px solid white; 
    padding:1em; 
    background-image: url(http://lorempixel.com/400/400/sports/1/); 
    background-position: center center; 

} 
2

它應用到HTML標籤將在全球範圍將此風格跨越別的你的HTML將包含。作爲一般的經驗法則,您應該明確地使用從不樣式您的HTML標記。這不是它的意圖。

應用過濾器的父元素內部的任何元素也會受到影響。

0

只是上的Photoshop 0.5的不透明度編輯您的背景圖片,先不談html標籤,並設置圖像作爲body背景圖片

0
<body> 
    <i class="shadow"></i> 
    <div class="button"> 
     <a href="#">START EXPERIENCE</a> 
</div> 
</body> 

CSS

body { 
    background: url(http://www.hdwallpapers.in/walls/cute_baby_in_autumn-wide.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 
} 
.shadow{ 
    position:absolute; 
    top:0; 
    left:0; 
    right:0; 
    bottom:0; 
    background-color: rgba(255, 0, 0, 0.5); 
    -webkit-filter: brightness(0.5); 
    filter: brightness(0.5); 
    -moz-filter: brightness(0.5); 
    -o-filter: brightness(0.5); 
    -ms-filter: brightness(0.5); 
} 

.button { 
    position: absolute; 
    left: 20%; 
    top: 50%; 
    z-index:2; 
} 

.button a { 
    text-decoration: none; 
    border: 2px solid white; 
    color: white; 
    padding-top: 25px; 
    padding-bottom: 25px; 
    padding-left: 100px; 
    padding-right: 100px; 
    -webkit-border-radius: 10px; 
    -moz-border-radius: 10px; 
    border-radius: 0; 
    text-transform: uppercase; 
    font-weight: bold; 
    font-size: 22px; 
    text-align:center; 
    white-space:nowrap; 
} 

.button a:hover { 
    background: white; 
    color: black; 
    color: rgba(0, 0, 0, 0.5); 
} 
相關問題