2017-02-14 155 views
2

我正在尋找將陰影只有應用於表格行之間的線條。在「紅色」線下面的示例中。我不希望陰影適用於藍色邊框。將陰影僅應用於表格行的頂部邊框

如果任何人都可以撥動下面的代碼片段來使它起作用,他們將成爲我今天的英雄。

編輯:我看到我的片段有尖銳的紅線問題。理想情況下,我實際上需要一條堅實的不分紅線。

這是哪門子的效果我在尋找: enter image description here

.shadow { 
 
    margin: 20px; 
 
    width: 80%; 
 
    background: yellow; 
 
    border-radius: 15px; 
 
    border: 2px solid blue; 
 
} 
 
.shadow td, .shadow th { 
 
    border-top: 5px solid red; 
 
    border-right: 2px solid blue; 
 
    padding: 10px; 
 
    text-align: center; 
 
} 
 
.shadow th { 
 
    border-top: none; 
 
} 
 
.shadow td:last-child, .shadow th:last-child { 
 
    border-right: none; 
 
}
<div> 
 
    <table class="shadow"> 
 
    <tr> 
 
     <th>AH</th> 
 
     <th>BH</th> 
 
     <th>CH</th> 
 
    </tr> 
 
    <tr> 
 
     <td>A1</td> 
 
     <td>B1</td> 
 
     <td>C1</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A2</td> 
 
     <td>B2</td> 
 
     <td>C2</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A3</td> 
 
     <td>B3</td> 
 
     <td>C3</td> 
 
    </tr> 
 
    </table> 
 
</div>

回答

1

這裏是我的貢獻,希望它幫助。 :)

.table { 
 
    margin: 20px; 
 
    width: 80%; 
 
    background: yellow; 
 
    border-radius: 15px; 
 
    border: 2px solid blue; 
 
    border-spacing: 0px; 
 
} 
 

 
.table tr { 
 
    box-shadow: 0 3px 4px -1px rgba(0,0,0,0.65); 
 
} 
 

 
.table th, .table td { 
 
    padding: 10px; 
 
    text-align: center; 
 
    border-bottom: 4px solid red; 
 
    border-right:2px solid blue; 
 
} 
 

 
.table tr:last-child td { 
 
    border-bottom: none; 
 
} 
 

 
.table tr td:last-child, 
 
.table tr th:last-child{ 
 
    border-right: none; 
 
} 
 

 
.table tr:last-child { 
 
    box-shadow: none; 
 
}
<div> 
 
    <table class="table"> 
 
    <tr> 
 
     <th>AH</th> 
 
     <th>BH</th> 
 
     <th>CH</th> 
 
    </tr> 
 
    <tr> 
 
     <td>A1</td> 
 
     <td>B1</td> 
 
     <td>C1</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A2</td> 
 
     <td>B2</td> 
 
     <td>C2</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A3</td> 
 
     <td>B3</td> 
 
     <td>C3</td> 
 
    </tr> 
 
    </table> 
 
</div>

+0

不錯,這是從一個角度來看最接近的一個,它的注意事項是1)右上角和左上角都有一個微弱的白色背景。 2)影子只在紅線之下,而不在上面。 3)與其他紅線一樣,陰影不等同於底部讀取線。這在片段運行時並不是很明顯,但是在調整它時(調整'box-shadow:0 3px 4px -1px rgba(0,0,0,0.65);'line)on jsfiddle就是非常明顯的了。 – Trevor

+0

我正在標記你的回答是正確的,即使上面提到的警告我也能達到很好的結果。(我使用的代碼有點短,也許我會張貼它作爲一點)再次感謝 – Trevor

+0

很高興我能夠幫助。 – Brad

2

在我看來,下面的代碼片段將解決您的問題。讓我知道,如果有什麼不好或你需要解釋的東西。基本上,我加入了盒陰影所有TD的和次的,然後我就用去除他們從最後一行:最後一子選擇

編輯:正如評論所說,我已經更新只增加

.shadow tr:not(:last-child) td, .shadow th{ 
    box-shadow: 0px 10px 5px rgba(0,0,0,0.6); 
} 

其中的伎倆以及

.shadow { 
 
    margin: 20px; 
 
    width: 80%; 
 
    background: yellow; 
 
    border-radius: 15px; 
 
    border: 2px solid blue; 
 
} 
 
.shadow td, .shadow th{ 
 
    border-top: 5px solid red; 
 
    border-right: 2px solid blue; 
 
    padding: 10px; 
 
    text-align: center; 
 
} 
 

 
.shadow tr:not(:last-child) td, .shadow th{ 
 
    box-shadow: 0px 10px 5px rgba(0,0,0,0.6); 
 
} 
 

 
.shadow th { 
 
    border-top: none; 
 
} 
 
.shadow td:last-child, .shadow th:last-child { 
 
    border-right: none; 
 
}
<div> 
 
    <table class="shadow"> 
 
    <tr> 
 
     <th>AH</th> 
 
     <th>BH</th> 
 
     <th>CH</th> 
 
    </tr> 
 
    <tr> 
 
     <td>A1</td> 
 
     <td>B1</td> 
 
     <td>C1</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A2</td> 
 
     <td>B2</td> 
 
     <td>C2</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A3</td> 
 
     <td>B3</td> 
 
     <td>C3</td> 
 
    </tr> 
 
    </table> 
 
</div>

+1

+1。你也可以應用一個':not(:last-child)'選擇器,以免你不必像你描述的那樣撤銷這個樣式。 – ne1410s

+0

你說得對,我已經更新了答案。沒有什麼大的差異我猜想,但仍然更簡單:) –

+0

謝謝,但也有一個明顯的藍色線條的影子,也看到我的評論Brads答案 – Trevor

1

您可以用使它僞元素和position: absolute

.shadow { 
 
    margin: 20px; 
 
    width: 80%; 
 
    background: yellow; 
 
    border-radius: 15px; 
 
    border: 2px solid blue; 
 
} 
 
.shadow td, .shadow th { 
 
    border-top: 5px solid red; 
 
    border-right: 2px solid blue; 
 
    padding: 10px; 
 
    text-align: center; 
 
    position: relative; 
 
} 
 
.shadow th { 
 
    border-top: none; 
 
} 
 
.shadow td:last-child, .shadow th:last-child { 
 
    border-right: none; 
 
} 
 
.shadow td:after, .shadow th:after { 
 
    content: ''; 
 
    display: block; 
 
    box-shadow: black 1px 3px 3px; 
 
    height: 2px; 
 
    width: 100%; 
 
    position: absolute; 
 
    left: 0; 
 
    bottom: 0; 
 
} 
 

 
.shadow tr:last-child td:after, .shadow tr:last-child th:after { 
 
    display: none; 
 
}
<div> 
 
    <table class="shadow"> 
 
    <tr> 
 
     <th>AH</th> 
 
     <th>BH</th> 
 
     <th>CH</th> 
 
    </tr> 
 
    <tr> 
 
     <td>A1</td> 
 
     <td>B1</td> 
 
     <td>C1</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A2</td> 
 
     <td>B2</td> 
 
     <td>C2</td> 
 
    </tr> 
 
    <tr> 
 
     <td>A3</td> 
 
     <td>B3</td> 
 
     <td>C3</td> 
 
    </tr> 
 
    </table> 
 
</div>

+0

這也很好,但我仍然更喜歡Brads。這一個也有不在紅線上方和下方的陰影。還有一些錯誤的紅線,有些出現在他們的最後傾斜。 – Trevor

+0

我看到我的原始代碼段也有尖銳的紅線問題。理想情況下,我實際上想要一條堅實的非分紅線 – Trevor