2015-12-24 77 views
0

我的問題很奇怪,但很簡單。我得到了一個類navbaritem的div,出於某種原因,過渡規則適用於邊距,但不適用於背景。CSS轉換不適用於背景

這裏的HTML和CSS

* { 
 
    font-family: Raleway, Century Gothic; 
 
} 
 

 
body { 
 
    margin: 0px; 
 
} 
 

 
a { 
 
    text-decoration: none; 
 
    color: #fff; 
 
} 
 

 
header > ul > li { 
 
    margin-bottom: 5vh; 
 
} 
 

 
.navbaritem { 
 
    position: absolute; 
 
    width: 30vw; 
 
    height: 6vh; 
 
    margin-left: -8vw; 
 
    -webkit-transform: skew(-30deg); 
 
    -moz-transform: skew(-30deg); 
 
    -o-transform: skew(-30deg); 
 
    
 
    background: rgb(245,246,246); 
 
    background: -moz-linear-gradient(top, rgba(245,246,246,1) 0%, rgba(219,220,226,1) 21%, rgba(184,186,198,1) 49%, rgba(221,223,227,1) 80%, rgba(245,246,246,1) 100%); 
 
    background: -webkit-linear-gradient(top, rgba(245,246,246,1) 0%,rgba(219,220,226,1) 21%,rgba(184,186,198,1) 49%,rgba(221,223,227,1) 80%,rgba(245,246,246,1) 100%); 
 
    background: linear-gradient(to bottom, rgba(245,246,246,1) 0%,rgba(219,220,226,1) 21%,rgba(184,186,198,1) 49%,rgba(221,223,227,1) 80%,rgba(245,246,246,1) 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f5f6f6', endColorstr='#f5f6f6',GradientType=0); 
 
    
 
    transition: 0.4s ease; 
 
} 
 

 
.navbaritem:hover { 
 
    margin-left: -3vw; 
 
    transition: 0.4s ease; 
 
} 
 

 
.navbaritem > a { 
 
    height: 80%; 
 
    margin-top: 1%; 
 
    margin-left: -10%; 
 
    width: 90%; 
 
    background: url(../img/graystripes.jpg); 
 
    box-shadow: inset 3vh 1vh 3vh #000; 
 
    -webkit-transform: skew(30deg); 
 
    -moz-transform: skew(30deg); 
 
    -o-transform: skew(30deg); 
 
    position: absolute; 
 
    text-align: center; 
 
    font-size: 4vh; 
 
} 
 

 

 
.navbaritem:hover { 
 
    transition: 0.4s ease; 
 
    
 
    background: rgb(255,0,0); 
 
    background: -moz-linear-gradient(top, rgba(255,0,0,1) 0%, rgba(247,0,0,1) 21%, rgba(137,0,0,1) 49%, rgba(247,0,0,1) 80%, rgba(255,0,0,1) 100%); 
 
    background: -webkit-linear-gradient(top, rgba(255,0,0,1) 0%,rgba(247,0,0,1) 21%,rgba(137,0,0,1) 49%,rgba(247,0,0,1) 80%,rgba(255,0,0,1) 100%); 
 
    background: linear-gradient(to bottom, rgba(255,0,0,1) 0%,rgba(247,0,0,1) 21%,rgba(137,0,0,1) 49%,rgba(247,0,0,1) 80%,rgba(255,0,0,1) 100%); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0000', endColorstr='#ff0000',GradientType=0); 
 
} 
 

 
.navbaritem > i { 
 
    font-size: 5vh; 
 
    color: #444; 
 
    margin-top: 1%; 
 
    margin-left: 85%; 
 
    
 
    -webkit-transform: skew(30deg); 
 
    -moz-transform: skew(30deg); 
 
    -o-transform: skew(30deg); 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta charset="UTF-8"> 
 
     <meta name="description" content="Offizielle Website von TesseractLabs"> 
 
     <meta name="author" content="Alexander Heuwes"> 
 
     
 
     <title>TesseractLabs | Home</title> 
 
     
 
     <link type="text/css" rel="stylesheet" href="css/style.css"> 
 
     <link type="text/css" rel="stylesheet" href="css/hover.css"> 
 
     <link type="text/css" rel="stylesheet" href="css/font-awesome.css"> 
 
     <link type="text/css" rel="stylesheet" href="css/font-awesome.min.css"> 
 
     <link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Raleway:100,200,300,400,500,600,700,800,900"> 
 

 
     <script src="js/jquery-1.11.3.min.js"></script> 
 
     <script src="js/jquery-migrate-1.2.1.min.js"></script> 
 
     <script src="js/classie.js"></script> 
 
    </head> 
 
    <body> 
 
     <header> 
 
      <ul> 
 
       <li> 
 
        <div class="navbaritem"> 
 
         <a href="#">Home</a> 
 
         <i class="fa fa-home"></i> 
 
        </div> 
 
       </li> 
 
       <li> 
 
        <div class="navbaritem"> 
 
         <a href="#">Services</a> 
 
         <i class="fa fa-code"></i> 
 
        </div> 
 
       </li> 
 
       <li> 
 
        <div class="navbaritem"> 
 
         <a href="#">Pricing</a> 
 
         <i class="fa fa-money"></i> 
 
        </div> 
 
       </li> 
 
       <li> 
 
        <div class="navbaritem"> 
 
         <a href="#">References</a> 
 
         <i class="fa fa-flag"></i> 
 
        </div> 
 
       </li> 
 
      </ul> 
 

 
      <!--<div class="navbaritem"> 
 
       <a href="#">Home</a> 
 
       <i class="fa fa-home"></i> 
 
      </div>--> 
 
     </header> 
 
     
 
     <main> 
 

 
     </main> 
 
     
 
     <footer> 
 
      
 
     </footer> 
 
    </body> 
 
</html>

+1

梯度般的畫面,所以你不能直接轉換它們。你可以嘗試一些這裏提到的方法 - http://stackoverflow.com/questions/33918470/how-to-animate-gradient-background-smoothly/33938639#33938639 – Harry

回答

2

就我而言,你不能過渡漸變。一種方法是在完全相同的位置使用2個元素並分別應用2個不同的梯度。然後賦予一個元素不透明度爲1(默認情況下顯示爲漸變的元素),然後將該元素的不透明度淡入0,將其他元素淡入淡出1。但我不會推薦這個。

編輯我發現了一個解決方法在這裏:Use CSS3 transitions with gradient backgrounds

+1

謝謝,這工作! – TheLexoPlexx

+0

你能給我反饋我的答案嗎?我的解決方案工作還是鏈接解決方法? :) –

+0

對不起,儘管我在編輯之後閱讀了您的評論,但您的方式奏效,我現在有2個div,其中一個不透明:100%懸停。 – TheLexoPlexx