2017-05-15 46 views
0

我試圖在導航欄中實現凹凸,導航欄應該有一個方塊陰影...但是凹凸也需要它在底部...不知何故,我不能把導航欄後面的凹凸,這是一個已知的問題,或者我錯過了什麼?非常感謝。將陰影和z索引應用於絕對定位的元素

body { 
 
    background: beige; 
 
} 
 

 
.c-header { 
 
    background: white; 
 
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8); 
 
    height: 60px; 
 
    position: fixed; 
 
    width: 100%; 
 
    z-index: 9999; 
 
} 
 

 
.c-site-nav { 
 
    align-content: center; 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 
.c-site-nav ul { 
 
    margin-left: 0; 
 
} 
 
.c-site-nav__item { 
 
    display: flex; 
 
    justify-content: space-around; 
 
    list-style: none; 
 
    width: 40%; 
 
} 
 
.c-site-nav__item a { 
 
    font-size: 20px; 
 
    color: grey; 
 
    display: inline-block; 
 
    text-decoration: none; 
 
} 
 

 
.c-logo { 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    padding: 0; 
 
    position: absolute; 
 
    top: 15px; 
 
    width: 45px; 
 
    z-index: 1; 
 
} 
 
.c-logo::after { 
 
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8); 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    background: white; 
 
    border-radius: 50%; 
 
    content: ''; 
 
    height: 60px; 
 
    position: absolute; 
 
    width: 60px; 
 
    z-index: -100; 
 
}
<header class="c-header"> 
 
    <div class="c-logo"> 
 
    </div> 
 
    <nav class="c-site-nav"> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="/ueber_uns">asd</a></li> 
 
     <li><a href="/">asd</a></li> 
 
    </ul> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="tel:+49234234234">34234234</a></li> 
 
    </ul> 
 
    </nav> 
 
</header>

回答

0

很抱歉的混亂,我才意識到,實現它的最簡單的方法,將放置創建凸點擺脫對僞的頂部的另一個僞元素的(或掩蓋)凸塊

body { 
 
    background: beige; 
 
    margin: 0; 
 
} 
 

 
.c-header { 
 
    box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12); 
 
    background: white; 
 
    height: 45px; 
 
    width: 100%; 
 
    z-index: 9999; 
 
} 
 

 
.c-site-nav { 
 
    align-content: center; 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 
.c-site-nav ul { 
 
    margin-left: 0; 
 
} 
 
.c-site-nav__item { 
 
    display: flex; 
 
    justify-content: space-around; 
 
    list-style: none; 
 
    width: 40%; 
 
} 
 
.c-site-nav__item a { 
 
    font-size: 20px; 
 
    color: grey; 
 
    display: inline-block; 
 
    text-decoration: none; 
 
} 
 

 
.c-logo { 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    padding: 0; 
 
    position: absolute; 
 
    top: 10px; 
 
    width: 45px; 
 
    z-index: 1; 
 
} 
 
.c-logo::after { 
 
    box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12); 
 
    background: white; 
 
    border-radius: 50%; 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    content: ''; 
 
    height: 45px; 
 
    position: absolute; 
 
    width: 60px; 
 
    z-index: -1; 
 
} 
 

 
.c-logo::before { 
 
    background: white; 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    content: ''; 
 
    top: -10px; 
 
    height: 45px; 
 
    position: absolute; 
 
    width: 80px; 
 
    z-index: 1; 
 
}
<header class="c-header"> 
 
    <div class="c-logo"> 
 
</div> 
 
    <nav class="c-site-nav"> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">item</a></li> 
 
     <li><a href="/">item</a></li> 
 
     <li><a href="/">item</a></li> 
 
    </ul> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">item</a></li> 
 
     <li><a href="/">item</a></li> 
 
     <li><a href="/">item</a></li> 
 
    </ul> 
 
    </nav> 
 
</header>

的陰影
2

我不知道這是否是預期的結果,但是我設法得到這種通過將

<div class="c-logo"> 

頭部元素之外完成。

body { 
 
    background: beige; 
 
} 
 

 
.c-header { 
 
    background: white; 
 
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8); 
 
    height: 60px; 
 
    position: fixed; 
 
    width: 100%; 
 
    z-index: 9999; 
 
} 
 

 
.c-site-nav { 
 
    align-content: center; 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 
.c-site-nav ul { 
 
    margin-left: 0; 
 
} 
 
.c-site-nav__item { 
 
    display: flex; 
 
    justify-content: space-around; 
 
    list-style: none; 
 
    width: 40%; 
 
} 
 
.c-site-nav__item a { 
 
    font-size: 20px; 
 
    color: grey; 
 
    display: inline-block; 
 
    text-decoration: none; 
 
} 
 

 
.c-logo { 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    padding: 0; 
 
    position: absolute; 
 
    top: 15px; 
 
    width: 45px; 
 
    z-index: 1; 
 
} 
 
.c-logo::after { 
 
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8); 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    background: white; 
 
    border-radius: 50%; 
 
    content: ''; 
 
    height: 60px; 
 
    position: absolute; 
 
    width: 60px; 
 
    z-index: -100; 
 
}
<header class="c-header"> 
 
    </div> 
 
    <nav class="c-site-nav"> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="/ueber_uns">asd</a></li> 
 
     <li><a href="/">asd</a></li> 
 
    </ul> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="tel:+49234234234">34234234</a></li> 
 
    </ul> 
 
    </nav> 
 
</header> 
 
    <div class="c-logo">

+0

這是正確的解決方案 – pokeybit

+0

或刪除z-index:9999;從頭文件css – pokeybit

+1

謝謝@kevin我剛纔意識到整個想法不可能像這樣實現,因爲很明顯,來自酒吧的陰影現在也在凹凸處 – HendrikEng

0

改變 'C-標誌' 的風格。只有從1更改了Z-指數爲-1,希望這將幫助你

`.c-logo { 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    padding: 0; 
 
    position: absolute; 
 
    top: 15px; 
 
    width: 45px; 
 
    z-index: -1; 
 
}`

2

您對僞選擇:after分配box-shadow爲中心circle,你可以減少blur-radius特定元素如下所示,

box-shadow:offset-x | offset-y |模糊半徑|顏色

body { 
 
    background: beige; 
 
} 
 

 
.c-header { 
 
    background: white; 
 
    box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.8); 
 
    height: 60px; 
 
    position: fixed; 
 
    width: 100%; 
 
    z-index: 9999; 
 
} 
 

 
.c-site-nav { 
 
    align-content: center; 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 
.c-site-nav ul { 
 
    margin-left: 0; 
 
} 
 
.c-site-nav__item { 
 
    display: flex; 
 
    justify-content: space-around; 
 
    list-style: none; 
 
    width: 40%; 
 
} 
 
.c-site-nav__item a { 
 
    font-size: 20px; 
 
    color: grey; 
 
    display: inline-block; 
 
    text-decoration: none; 
 
} 
 

 
.c-logo { 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    padding: 0; 
 
    position: absolute; 
 
    top: 15px; 
 
    width: 45px; 
 
    z-index: 1; 
 
} 
 
.c-logo::after { 
 
    box-shadow: 0 2px 2px -2px rgba(0, 0, 0, 0.8); 
 
    position: absolute; 
 
    left: 50%; 
 
    transform: translate(-50%, 0); 
 
    background: white; 
 
    border-radius: 50%; 
 
    content: ''; 
 
    height: 60px; 
 
    position: absolute; 
 
    width: 60px; 
 
    z-index: -100; 
 
}
<header class="c-header"> 
 
    <div class="c-logo"> 
 
    </div> 
 
    <nav class="c-site-nav"> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="/ueber_uns">asd</a></li> 
 
     <li><a href="/">asd</a></li> 
 
    </ul> 
 
    <ul class="c-site-nav__item"> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="/">asd</a></li> 
 
     <li><a href="tel:+49234234234">34234234</a></li> 
 
    </ul> 
 
    </nav> 
 
</header>

+0

感謝@frnt,這是一個不錯的主意,但它會一直下降頂部標題上的一點陰影 – HendrikEng

+1

@HendrikEng如果你打算添加很多然後是,或者你可以保持減去模糊,直到你沒有得到計劃的效果。檢查這個https://jsfiddle.net/8wydo9z7/ – frnt

+0

再次感謝,它是一個好方法,但我想它具有像素完美的最簡單的方法是將另一個僞元素放在凹凸的頂部以覆蓋第一個元素的陰影。 – HendrikEng