2016-08-18 29 views
2

CSS懸停與框的陰影,因爲我需要

<style> 
 
.ui-state-active { 
 
    color: #fff; 
 
    background:red; 
 
    #box-shadow: inset -7px 7px 9px -7px #236c4d; 
 
    width:50px; 
 
    height:50px; 
 
} 
 
.ui-state-active:hover{ 
 
\t box-shadow: inset 15px 7px 9px -7px #fff; 
 
\t box-shadow: inset -7px 7px 9px -7px #fff; 
 
} 
 
</style> 
 
<div class="ui-state-active">18 
 
</div>

我需要這樣的東西,這是不工作,當我在一個div徘徊它顯示在右上角變換三角狀顯示圖像,我只是解釋了我作爲圖像要求清晰明確enter image description here

回答

4

你可以用僞元素做:before:after

.ui-state-active { 
 
    color: #fff; 
 
    background:red; 
 
    width:50px; 
 
    height:50px; 
 
    position: relative; 
 
} 
 
.ui-state-active:hover:after{ 
 
    content: ''; 
 
    position: absolute; 
 
    top: 3px; 
 
    right: 3px; 
 
    border: solid 10px white; 
 
    border-color: white white transparent transparent; 
 
}
<div class="ui-state-active">18 
 
</div>

+0

z0mBi3先生你是真棒,感謝ü老兄 –

+0

我也學會了一些有+ 1'ed你:) – Option

2

我不會用箱陰影,我會使用一個僞元素。

有幾種方法可以做到這一點。


1.一種位置,旋轉pseduo元素:

span { 
 
    display: block; 
 
    width: 3em; 
 
    height: 3em; 
 
    line-height: 3em; 
 
    text-align: center; 
 
    background: #f00; 
 
    color: white; 
 
    font-weight: bold; 
 
    margin: 3em auto; 
 
    overflow: hidden; 
 
    position: relative; 
 
} 
 
span::after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 100%; 
 
    height: 100%; 
 
    background: orange; 
 
    top: -100%; 
 
    left: 100%; 
 
    transform: rotate(45deg) translate(0%, 0%); 
 
    transition: transform .35s ease; 
 
} 
 
span:hover::after { 
 
    transform: rotate(45deg) translate(0%, 50%)
<span>16</span>


2.或者,僞元件完全由邊界

div { 
 
    display: block; 
 
    width: 3em; 
 
    height: 3em; 
 
    line-height: 3em; 
 
    text-align: center; 
 
    background: #f00; 
 
    color: white; 
 
    font-weight: bold; 
 
    margin: 3em auto; 
 
    overflow: hidden; 
 
    position: relative; 
 
} 
 
div::after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 0; 
 
    height: 0; 
 
    top: 0; 
 
    right: 0; 
 
    border-style: solid; 
 
    border-color: orange orange transparent transparent; 
 
    border-width: 0px; 
 
    transition: border-width .35s ease; 
 
} 
 
div:hover::after { 
 
    border-width: 12px; 
 
}
<div>16</div>

+0

謝謝U,Mr.Paulie_D,其作品對我很好 –

0

嘗試了這一點,:)

HTML

<div class="date"> 
    <div class="sideflip"></div> 
    18 
</div> 

CSS

.date 
{ 
    width:80px; 
    height:80px; 
    border:1px solid #000000; 
    text-align:center; 
    font-size:65px; 
    font-family: "Century Gothic", CenturyGothic, AppleGothic, sans-serif; 
    background:red; 
    color:#ffffff; 
    position:relative; 
    overflow:hidden; 
} 

.sideflip 
{ 
    width:50px; 
    height:50px; 
    font-size:1px; 
    position:absolute; 
    -ms-transform: rotate(-50deg); 
    -webkit-transform: rotate(-50deg); 
    transform: rotate(-50deg); 
    margin-left:160px; 
    margin-top:-130px; 
    background:#ffffff; 
    -webkit-transition: all 0.5s; 
    transition: all 0.5s; 
} 

.date:hover .sideflip 
{ 
    margin-left:60px; 
    margin-top:-30px; 
} 
.date:hover 
{ 
    cursor:pointer; 
} 

Here is the Snap