mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-09-09 22:00:53 +02:00
feat: Sticky table column
This commit is contained in:
11
contents/_includes/patterns/sticky-table-column.njk
Normal file
11
contents/_includes/patterns/sticky-table-column.njk
Normal file
@@ -0,0 +1,11 @@
|
||||
<table class="sticky-table-column">
|
||||
<tbody>
|
||||
{% for i in range(0, 3) -%}
|
||||
<tr>
|
||||
<td class="sticky-table-column__sticky">{% rectangle %}</td>
|
||||
<td>{% lines "hor", 3 %}</td>
|
||||
<td>{% lines "hor", 2 %}</td>
|
||||
</tr>
|
||||
{%- endfor %}
|
||||
</tbody>
|
||||
</table>
|
@@ -265,6 +265,12 @@ eleventyExcludeFromCollections: true
|
||||
<div class="pattern__title">Status light</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pattern__item">
|
||||
<a class="pattern__link" href="/sticky-table-column/">
|
||||
<div class="pattern__cover">{% include "patterns/sticky-table-column.njk" %}</div>
|
||||
<div class="pattern__title">Sticky table column</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pattern__item">
|
||||
<a class="pattern__link" href="/teardrop/">
|
||||
<div class="pattern__cover">{% include "patterns/teardrop.njk" %}</div>
|
||||
|
48
contents/sticky-table-column.md
Normal file
48
contents/sticky-table-column.md
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Sticky table column
|
||||
description: Create sticky table column with CSS
|
||||
keywords: css position sticky, css sticky table column
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<table class="sticky-table-column">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="sticky-table-column__sticky">
|
||||
...
|
||||
</th>
|
||||
|
||||
<!-- Other header column ... -->
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="sticky-table-column__sticky">...</td>
|
||||
<!-- Other columns -->
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.sticky-table-column__sticky {
|
||||
/* Background color */
|
||||
background-color: #9ca3af;
|
||||
|
||||
/* Stick to the left */
|
||||
left: 0;
|
||||
position: sticky;
|
||||
|
||||
/* Displayed on top of other rows when scrolling */
|
||||
z-index: 9999;
|
||||
}
|
||||
```
|
||||
|
||||
{% demo %}
|
||||
{% include "patterns/sticky-table-column.njk" %}
|
||||
{% enddemo %}
|
Reference in New Issue
Block a user