2014-07-08 42 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); 
} 
相关问题