2017-07-07 77 views
0

我遇到了一些奇怪的問題。在我的代碼中,按鈕css動畫只有在margin-top設置爲125px(對於sim-button類)時纔有效。我想把margin-top縮小到25px,但是動畫不起作用。按鈕動畫僅適用於特定保證金

Codepen Here

HTML:

<div class="media" style = "background-color:#000;"> 
          <img class="media__image" src="https://www.offensive-security.com/wp-content/uploads/2012/01/security-risk-assessment-report.png"> 
          <div class="media__body"> 
          <h2>Penetration Report</h2> 
          <p>Get your hands on our Sample Presentation Report</p> 
          <div class="sim-button button1" data-toggle="modal" data-target="#getQuoteModal">Download Report</div> 
          </div> 
         </div> 

CSS:

.media { 
    display: inline-block; 
    position: relative; 
    vertical-align: top; 
} 

.media__image { display: block; } 

.media__body { 
    background: rgba(41, 128, 185, 0.7); 
    bottom: 0; 
    color: white; 
    font-size: 1em; 
    left: 0; 
    opacity: 0; 
    overflow: hidden; 
    padding: 3.75em 3em; 
    position: absolute; 
    text-align: center; 
    top: 0; 
    right: 0; 
    -webkit-transition: 0.6s; 
    transition: 0.6s; 
} 

.media__body:hover { opacity: 1; } 

.media__body:after, 
.media__body:before { 
    border: 1px solid rgba(255, 255, 255, 0.7); 
    bottom: 1em; 
    content: ''; 
    left: 1em; 
    opacity: 0; 
    position: absolute; 
    right: 1em; 
    top: 1em; 
    -webkit-transform: scale(1.5); 
    -ms-transform: scale(1.5); 
    transform: scale(1.5); 
    -webkit-transition: 0.6s 0.2s; 
    transition: 0.6s 0.2s; 
} 

.media__body:before { 
    border-bottom: none; 
    border-top: none; 
    left: 2em; 
    right: 2em; 
} 

.media__body:after { 
    border-left: none; 
    border-right: none; 
    bottom: 2em; 
    top: 2em; 
} 

.media__body:hover:after, 
.media__body:hover:before { 
    -webkit-transform: scale(1); 
    -ms-transform: scale(1); 
    transform: scale(1); 
    opacity: 1; 
} 

.media__body h2 { margin-top: 0; } 

.media__body p { margin-bottom: 0em; } 





.sim-button{ 
    line-height: 50px; 
    height: 50px; 
    text-align: center; 
    margin-right: auto; 
    margin-left: auto; 
    margin-top: 125px; 
    width: 60%; 
    cursor: pointer; 
} 
.button1 { 
    color: rgba(255,255,255,1); 
    -webkit-transition: all 0.5s; 
    -moz-transition: all 0.5s; 
    -o-transition: all 0.5s; 
    transition: all 0.5s; 
    position: relative; 
    border: 1px solid rgba(255,255,255,0.5); 
} 
.button1 a{ 
    color: rgba(51,51,51,1); 
    text-decoration: none; 
    display: block; 
} 
.button1:hover { 
    background-color: rgba(255,255,255,0.2); 
    -webkit-border-radius: 25px; 
    -moz-border-radius: 25px; 
    border-radius: 25px;  
} 

感謝提前的幫助。

回答

3

你的按鈕被隱藏的疊加之下:

z-index: 1; 

投入到上述的SIM-按鈕類得到你想要的效果。它將您的按鈕帶到前臺,並且可以通過旋轉來激活動畫。

這裏是我的變化作出了小提琴加入: jsfiddle

0

另一種方式來做到這一點,如果你想要的文字是可選擇和按鈕效果工作,可以點擊是設置z-index: 1.media__body,然後z-index: -1上的::before/::after僞元素。這將忘卻所有內容的僞元素.media__body,但讓他們從去後面.media__body

.media { 
 
    display: inline-block; 
 
    position: relative; 
 
    vertical-align: top; 
 
} 
 

 
.media__image { 
 
    display: block; 
 
} 
 

 
.media__body { 
 
    background: rgba(41, 128, 185, 0.7); 
 
    bottom: 0; 
 
    color: white; 
 
    font-size: 1em; 
 
    left: 0; 
 
    opacity: 0; 
 
    overflow: hidden; 
 
    padding: 3.75em 3em; 
 
    position: absolute; 
 
    text-align: center; 
 
    top: 0; 
 
    right: 0; 
 
    -webkit-transition: 0.6s; 
 
    transition: 0.6s; 
 
    z-index: 1; 
 
} 
 

 
.media__body:hover { 
 
    opacity: 1; 
 
} 
 

 
.media__body:after, .media__body:before { 
 
    border: 1px solid rgba(255, 255, 255, 0.7); 
 
    bottom: 1em; 
 
    content: ''; 
 
    left: 1em; 
 
    opacity: 0; 
 
    position: absolute; 
 
    right: 1em; 
 
    top: 1em; 
 
    -webkit-transform: scale(1.5); 
 
    -ms-transform: scale(1.5); 
 
    transform: scale(1.5); 
 
    -webkit-transition: 0.6s 0.2s; 
 
    transition: 0.6s 0.2s; 
 
    z-index: -1; 
 
} 
 

 
.media__body:before { 
 
    border-bottom: none; 
 
    border-top: none; 
 
    left: 2em; 
 
    right: 2em; 
 
} 
 

 
.media__body:after { 
 
    border-left: none; 
 
    border-right: none; 
 
    bottom: 2em; 
 
    top: 2em; 
 
} 
 

 
.media__body:hover:after, .media__body:hover:before { 
 
    -webkit-transform: scale(1); 
 
    -ms-transform: scale(1); 
 
    transform: scale(1); 
 
    opacity: 1; 
 
} 
 

 
.media__body h2 { 
 
    margin-top: 0; 
 
} 
 

 
.media__body p { 
 
    margin-bottom: 0em; 
 
} 
 

 
.sim-button { 
 
    line-height: 50px; 
 
    height: 50px; 
 
    text-align: center; 
 
    margin-right: auto; 
 
    margin-left: auto; 
 
    margin-top: 25px; 
 
    width: 60%; 
 
    cursor: pointer; 
 
} 
 
.button1 { 
 
    color: rgba(255, 255, 255, 1); 
 
    -webkit-transition: all 0.5s; 
 
    -moz-transition: all 0.5s; 
 
    -o-transition: all 0.5s; 
 
    transition: all 0.5s; 
 
    position: relative; 
 
    border: 1px solid rgba(255, 255, 255, 0.5); 
 
} 
 
.button1 a { 
 
    color: rgba(51, 51, 51, 1); 
 
    text-decoration: none; 
 
    display: block; 
 
} 
 
.button1:hover { 
 
    background-color: rgba(255, 255, 255, 0.2); 
 
    -webkit-border-radius: 25px; 
 
    -moz-border-radius: 25px; 
 
    border-radius: 25px; 
 
}
<div class="media" style="background-color:#000;"> 
 
    <img class="media__image" src="https://www.offensive-security.com/wp-content/uploads/2012/01/security-risk-assessment-report.png"> 
 
    <div class="media__body"> 
 
    <h2>Penetration Report</h2> 
 
    <p>Get your hands on our Sample Presentation Report</p> 
 
    <div class="sim-button button1" data-toggle="modal" data-target="#getQuoteModal">Download Report</div> 
 
    </div> 
 
</div>