2015-02-07 63 views
3

刪節解釋

昨晚我正在複製我發現的一個有趣的Codepen。完成之後,我對它的工作非常滿意。由於我不打算在製作中使用它,我忽略了使用適當的CSS前綴來確保跨瀏覽器兼容性。然而,當我決定在Safari和Firefox中檢查它時,我發現我的「:懸停」事件沒有正確翻譯,到目前爲止我一直無法修復它。我不需要這個項目,但我希望能找到一些幫助,找出爲什麼會發生這種情況,所以我可以準備在未來的發展中解決這個問題。選擇器無法正確地從Chrome瀏覽器轉換爲Firefox和Safari

直接問題

在Firefox和Safari,當您將鼠標放在那些對「飛出」菜單標題,他們崩潰的權利,而在Chrome中他們仍然出來的菜單項。

我想強調一下,我明白爲什麼某些功能(如轉換)不起作用,因爲我沒有爲大多數功能指定「webkit」或「moz」前綴。這簡直就是令我困擾的摺疊菜單。

代碼

ul.sidebar { 
 
    display: block; 
 
    position: absolute; 
 
    margin: 0; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 6.5em; 
 
    background: #aa2266; 
 
    padding: 0; 
 
    text-align: center; 
 
} 
 
ul.sidebar * { 
 
    -webkit-touch-callout: none; 
 
    -webkit-user-select: none; 
 
    -khtml-user-select: none; 
 
    -moz-user-select: none; 
 
    -ms-user-select: none; 
 
    user-select: none; 
 
} 
 
ul.sidebar a { 
 
    color: white; 
 
    text-decoration: none; 
 
    margin: 0; 
 
    display: inline-block; 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 
ul.sidebar a > i { 
 
    margin-top: 0.13333em; 
 
    font-size: 2em; 
 
    display: block; 
 
    margin-bottom: 0.2em; 
 
} 
 
ul.sidebar a > span { 
 
    font-size: 0.8em; 
 
    font-family: sans-serif; 
 
} 
 
ul.sidebar li { 
 
    transition: background 0.3s; 
 
    background: #aa2266; 
 
} 
 
ul.sidebar > li { 
 
    margin: 0; 
 
    padding: 0; 
 
    height: 4em; 
 
    display: inline-block; 
 
    position: relative; 
 
    width: 100%; 
 
    background: #aa2266; 
 
    transition: background 0.3s; 
 
} 
 
ul.sidebar > li:hover { 
 
    background: #dc3278; 
 
} 
 
ul.sidebar > li:hover:after { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 100%; 
 
    width: 6px; 
 
    background: linear-gradient(to right, rgba(0, 0, 0, 0.25) 0%, transparent 100%); 
 
} 
 
ul.sidebar > li > a { 
 
    transition: background 0.3s; 
 
} 
 
ul.sidebar > li > a:hover { 
 
    background: #ff5f87; 
 
} 
 
ul.sidebar > li > ul { 
 
    overflow: hidden; 
 
    height: 4em; 
 
    padding: 0; 
 
    position: absolute; 
 
    z-index: -1; 
 
    margin: 0; 
 
    color: red; 
 
    left: 100%; 
 
    transition-delay: 0.3s; 
 
    transition-property: transform; 
 
    transition-duration: 0.6s; 
 
    -webkit-transform: translateX(-100%); 
 
    transform: translateX(-100%); 
 
    width: auto; 
 
    list-style: none; 
 
    white-space: nowrap; 
 
    top: 0; 
 
    background: #dc3278; 
 
} 
 
ul.sidebar > li > ul > li { 
 
    overflow: hidden; 
 
    background: none; 
 
    margin: 0 0px 0 -4px; 
 
    padding: 0; 
 
    display: inline-block; 
 
    width: 6.5em; 
 
    height: 4em; 
 
    transition: background 0.3s; 
 
} 
 
ul.sidebar > li > ul > li:hover { 
 
    background: #fa648c; 
 
} 
 
ul.sidebar li:hover > ul { 
 
    -webkit-transform: translateX(0); 
 
    transform: translateX(0); 
 
} 
 
ul.sidebar li:hover > ul > li { 
 
    color: white; 
 
} 
 

 
body { 
 
    padding: 0; 
 
    position: fixed; 
 
    margin: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    background: #450f30; 
 
} 
 

 
description { 
 
    position: absolute; 
 
    bottom: 0; 
 
    right: 0; 
 
    padding: 0 0.4em 1em 0; 
 
    color: white; 
 
    font-size: 20px; 
 
    font-family: times new roman; 
 
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> 
 
<description> 
 
    Full Stack Developer 
 
</description> 
 

 

 

 
<ul class="sidebar"> 
 
    <li> 
 
    <a href="#"> 
 
     <i class="fa fa-home"></i> 
 
     <span> 
 
    My Projects 
 
     </span> 
 
     
 
    </a> 
 
    <ul> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-question-circle"></i> 
 
      <span>Nothing</span> 
 
     </a> 
 
     
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-square"></i> 
 
      <span>Boxes for all</span> 
 
     </a> 
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-th-large"></i> 
 
      <span>More boxes</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
    </li> 
 
    <li> 
 
    <a> 
 
     <i class="fa fa-info-circle"></i> 
 
     <span> 
 
     About 
 
     </span> 
 
    </a> 
 
    
 
    <ul> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-eye"></i> 
 
      <span>I have eyes</span> 
 
     </a> 
 
     
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-bed"></i> 
 
      <span>and a bed</span> 
 
     </a> 
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-heartbeat"></i> 
 
      <span>plus cool icons</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
    </li> 
 
    <li> 
 
    <a> 
 
     <i class="fa fa-globe"> 
 
     </i> 
 
     <span> 
 
     Links 
 
     </span> 
 
    </a> 
 
    <ul> 
 
    <li> 
 
     <a> 
 
      <i class="fa fa-external-link"></i> 
 
      <span>No Links</span> 
 
     </a> 
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-fire"></i> 
 
      <span>For the wicked</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
    </li> 
 
    <li> 
 
    <a> 
 
    <i class="fa fa-envelope-o"></i> 
 
    <span> 
 
    Contact 
 
    </span> 
 
    </a> 
 
    <ul> 
 
     <li> 
 
     <a href="mailto:[email protected]"> 
 
      <i class="fa fa-user"></i> 
 
      <span style="font-size: 8px;">[email protected]</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
</li> 
 
    </ul>

Code Pen
+0

看起來Firefox並沒有意識到,在翻譯之後,光標仍在懸停。如果添加ul.sidebar li,會發生什麼情況:hover> hover:hover {transform:translateX(0); }? – bobdye 2015-02-07 20:21:20

回答

2

問題不用於變換和過渡賣主前綴。問題是z-index: -1財產。根據定義,具有絕對位置的元素應位於內聯或相對的所有元素之上。使用-1的技巧工作並將其放置在具有位置相對的父菜單元素下面。但是,在Firefox和IE中,它甚至放置在身體下方,所以當鼠標懸停在放置菜單上時,實際上懸停在身體​​上,即出於父菜單<li>元素。

爲了解決這個問題,我所做的更改:

ul.sidebar > li > a類改爲z-index爲1,並增加了下列屬性ul.sidebar > li > a類:

position: absolute; 
    left: 0; 
    background: #aa2266; 
    z-index: 1; 

我就檢查結果Firefox和Internet Explorer,現在,它工作得很好:)

ul.sidebar { 
 
    display: block; 
 
    position: absolute; 
 
    margin: 0; 
 
    left: 0; 
 
    height: 100%; 
 
    width: 6.5em; 
 
    background: #aa2266; 
 
    padding: 0; 
 
    text-align: center; 
 
} 
 
ul.sidebar * { 
 
    -webkit-touch-callout: none; 
 
    -webkit-user-select: none; 
 
    -khtml-user-select: none; 
 
    -moz-user-select: none; 
 
    -ms-user-select: none; 
 
    user-select: none; 
 
} 
 
ul.sidebar a { 
 
    color: white; 
 
    text-decoration: none; 
 
    margin: 0; 
 
    display: inline-block; 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 
ul.sidebar a > i { 
 
    margin-top: 0.13333em; 
 
    font-size: 2em; 
 
    display: block; 
 
    margin-bottom: 0.2em; 
 
} 
 
ul.sidebar a > span { 
 
    font-size: 0.8em; 
 
    font-family: sans-serif; 
 
} 
 
ul.sidebar li { 
 
    transition: background 0.3s; 
 
    background: #aa2266; 
 
} 
 
ul.sidebar > li { 
 
    margin: 0; 
 
    padding: 0; 
 
    height: 4em; 
 
    display: inline-block; 
 
    position: relative; 
 
    width: 100%; 
 
    background: #aa2266; 
 
    transition: background 0.3s; 
 
} 
 
ul.sidebar > li:hover { 
 
    background: #dc3278; 
 
} 
 
ul.sidebar > li:hover:after { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 100%; 
 
    width: 6px; 
 
    background: linear-gradient(to right, rgba(0, 0, 0, 0.25) 0%, transparent 100%); 
 
} 
 
ul.sidebar > li > a { 
 
    position: absolute; 
 
    left: 0; 
 
    background: #aa2266; 
 
    z-index: 1; 
 
    transition: background 0.3s; 
 
} 
 
ul.sidebar > li > a:hover { 
 
    background: #ff5f87; 
 
} 
 
ul.sidebar > li > ul { 
 
    overflow: hidden; 
 
    height: 4em; 
 
    padding: 0; 
 
    position: absolute; 
 
    z-index: 0; 
 
    margin: 0; 
 
    color: red; 
 
    left: 100%; 
 
    transition-delay: 0.3s; 
 
    transition-property: transform; 
 
    transition-duration: 0.6s; 
 
    -webkit-transform: translateX(-100%); 
 
    transform: translateX(-100%); 
 
    width: auto; 
 
    list-style: none; 
 
    white-space: nowrap; 
 
    top: 0; 
 
    background: #dc3278; 
 
} 
 
ul.sidebar > li > ul > li { 
 
    overflow: hidden; 
 
    background: none; 
 
    margin: 0 0px 0 -4px; 
 
    padding: 0; 
 
    display: inline-block; 
 
    width: 6.5em; 
 
    height: 4em; 
 
    transition: background 0.3s; 
 
} 
 
ul.sidebar > li > ul > li:hover { 
 
    background: #fa648c; 
 
} 
 
ul.sidebar li:hover > ul { 
 
    -webkit-transform: translateX(0); 
 
    transform: translateX(0); 
 
} 
 
ul.sidebar li:hover > ul > li { 
 
    color: white; 
 
} 
 

 
body { 
 
    padding: 0; 
 
    position: fixed; 
 
    margin: 0; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    background: #450f30; 
 
} 
 

 
description { 
 
    position: absolute; 
 
    bottom: 0; 
 
    right: 0; 
 
    padding: 0 0.4em 1em 0; 
 
    color: white; 
 
    font-size: 20px; 
 
    font-family: times new roman; 
 
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> 
 
<description> 
 
    Full Stack Developer 
 
</description> 
 

 

 

 
<ul class="sidebar"> 
 
    <li> 
 
    <a href="#"> 
 
     <i class="fa fa-home"></i> 
 
     <span> 
 
    My Projects 
 
     </span> 
 
     
 
    </a> 
 
    <ul> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-question-circle"></i> 
 
      <span>Nothing</span> 
 
     </a> 
 
     
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-square"></i> 
 
      <span>Boxes for all</span> 
 
     </a> 
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-th-large"></i> 
 
      <span>More boxes</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
    </li> 
 
    <li> 
 
    <a> 
 
     <i class="fa fa-info-circle"></i> 
 
     <span> 
 
     About 
 
     </span> 
 
    </a> 
 
    
 
    <ul> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-eye"></i> 
 
      <span>I have eyes</span> 
 
     </a> 
 
     
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-bed"></i> 
 
      <span>and a bed</span> 
 
     </a> 
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-heartbeat"></i> 
 
      <span>plus cool icons</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
    </li> 
 
    <li> 
 
    <a> 
 
     <i class="fa fa-globe"> 
 
     </i> 
 
     <span> 
 
     Links 
 
     </span> 
 
    </a> 
 
    <ul> 
 
    <li> 
 
     <a> 
 
      <i class="fa fa-external-link"></i> 
 
      <span>No Links</span> 
 
     </a> 
 
     </li> 
 
     <li> 
 
     <a> 
 
      <i class="fa fa-fire"></i> 
 
      <span>For the wicked</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
    </li> 
 
    <li> 
 
    <a> 
 
    <i class="fa fa-envelope-o"></i> 
 
    <span> 
 
    Contact 
 
    </span> 
 
    </a> 
 
    <ul> 
 
     <li> 
 
     <a href="mailto:[email protected]"> 
 
      <i class="fa fa-user"></i> 
 
      <span style="font-size: 8px;">[email protected]</span> 
 
     </a> 
 
     </li> 
 
    </ul> 
 
</li> 
 
    </ul>

+0

我沒有意識到它,直到我更新我的codepen,但你的代碼刪除了我建立在滑塊中的透明效果。所以爲了保持這種效果,我不得不將身體的位置改變爲「靜態」,並保持其餘的代碼相同。儘管你的回答並沒有完全解決我的問題,但它仍然解釋了我做錯了什麼,並且非常有幫助。謝謝您的回覆。 – Alec 2015-02-07 23:38:26

+0

當然沒有人可以最終修復你的代碼比你自己更好。我只幫你指出了問題:) – 2015-02-07 23:54:48

相關問題