2014-09-04 76 views
0

Hint如何移动盒子阴影?

这是CSS它是如何描述

.hint { 
background: url('/triangle.png') center right no-repeat; 
padding-right: 10px; 
box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.25); 
} 

如何移动留下了阴影10px的?

回答

3

你可以用CSS(不需要的图像)做这一切:

.hint { 
    background:#F85B58; 
    display:inline-block; 
    position:relative; 
    color:white; 
    padding:20px; 
    box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.25); 
} 
.hint:before, .hint:after { 
    content:" "; 
    display:block; 
    position:absolute; 
    top:50%; 
    left:100%; 
    width:0px; 
    height:0px; 
    overflow:hidden; 
    margin-top:-10px; 
    border:10px solid transparent; 
    border-left-color:#F85B58; 
} 
.hint:before { 
    margin-top:-8px; 
    border-left-color:rgba(0, 0, 0, 0.25); 
} 

参见:http://jsfiddle.net/ro9nfhw6/

更改border-width使箭头更严重(根据你的榜样):

.hint:before, .hint:after { 
    border-width:6px 10px; 
} 

例如:http://jsfiddle.net/ro9nfhw6/1/

+0

请记住,支持:之前和之后:在旧版浏览器中并不好,如果它存在的话。 – evilunix 2014-09-04 14:48:56

+0

@evilunix注意到,但支持是相当不错的 - [回到IE8事实上](http://caniuse.com/#feat=css-gencontent) – Moob 2014-09-04 14:51:57

0
.hint-outer { 
    background: url('/triangle.png') center right no-repeat; 
    padding-right: 10px; 
} 

.hint-inner { 
    box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.25); 
    height: 100px; 
} 


<div class="hint-outer"><div class="hint-inner"></div></div> 
+0

问题是,您需要将您的标记拆分为多个div,然后单独对它们应用阴影。框阴影将始终适用于整个div,即使它的一部分对您来说看起来是透明的。 – evilunix 2014-09-04 14:38:49

+0

它移动了一个影子,但影子出现在左侧 – Alexey 2014-09-04 14:41:57

+0

问题影子在右下角?你需要将你的代码分割成一个外部和一个内部DIV,并且只把阴影应用到内部DIV上。 – evilunix 2014-09-04 14:44:26