jrarrmy

https://www.reddit.com/r/HTML/comments/1f939bw/this_table_cell_scroll_problem_has_been_bugging/

by Vince Aggrippino

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Table Example</title>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>Play Link</th>
                <th>Title</th>
                <th>Description</th>
                <th>Genre</th>
                <th>Year</th>
                <th>Artist</th>
                <th>Project</th>
                <th>Language</th>
                <th>Rating</th>
            </tr>
        </thead>
        <tbody>
            <tr data-title="Psalm 66:1-20" data-year="2024" data-artist="Shane Heilman">
                <td class="play-link">
                    <a href="UNRELEASED" title="" class="popup-link" data-url="UNRELEASED">▶</a>
                </td>
                <td>Psalm 66:1-20</td>
                <td class="scrollable-cell">
                    <div>
                        God Saves Us, His People, and the World, Miraculous Deliverance
                    </div>
                </td>
                <td class="scrollable-cell">
                    <div>
                        90s Worship Rock
                    </div>
                </td>
                <td><center>2024</center></td>
                <td class="scrollable-cell">
                    <div>
                        Shane Heilman
                    </div>
                </td>
                <td><center><a href="https://www.thepsalmsproject.com">The Psalms Project</a></center></td>
                <td><center><a href="?Lang=English" title="English" class="nounder">🇬🇧</a></center></td>
                <td>
                    <div class="rating">
                        <span class="rating-star" title="0 votes at 0.00">&#9733;</span>
                        <span class="rating-star" title="0 votes at 0.00">&#9733;</span>
                        <span class="rating-star" title="0 votes at 0.00">&#9733;</span>
              ...

CSS

table {
    --row-height: 30px;
    --cell-padding: 4px;
    --scrollable-width: 200px;
    border-collapse: collapse;
    width: 100%;
}

th, td {
    border: 1px solid black;
    padding: var(--cell-padding);
    
    /* box-sizing: border-box; */
    /* Includes padding and border in element's total width and height */
    /**
     * border-box has no effect on table cells
     */
    height: var(--row-height);
}

.play-link {
    text-align: center;
    vertical-align: middle;
}

.scrollable-cell {
    /**
     * You can't set height for table cells individually.
     */
    /*
    max-height: 30px;
    max-width: 200px;
    */
    & > div {
        font-size: 1rem;
        width: var(--scrollable-width);
        white-space: nowrap;
        overflow: auto hidden;
        height: var(--row-height);
        outline: 1px solid red;
    }
    
    /* Adjust as needed */
    /*
    overflow: auto;
    display: block;
    */
    /* Ensures the cell can scroll */
    white-space: normal;
    /* Allows text to wrap */
    text-overflow: ellipsis;
    /* Adds '...' for overflowed text */
}

.rating-star {
    font-size: 1em;
}

.rating {
    display: flex;
    align-items: center;
    justify-content: center;
}

.rating-text {
    margin-left: 5px;
}

/* Ensure table rows have the same height */
tr {
    height: 30px;
}