Styling CSS for a overflowing HTML table

I've been working on formatting a small HTML table like the example below:

.table {
  max-height: 160px;
  display: block;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  overflow: auto;
  border: 1px solid gray;
}

.table-body {
  max-height: 100%;
}

.row {
  width: 100%;
  display: block;
}

.row.headers {
  background: #ddd;
  font-weight: 600;
  position: sticky;
  top: 0;
}

.row:nth-child(2n) {
  background: #f1efef;
}

.cell {
  text-overflow: ellipsis;
  display: table-cell;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  padding: 2px 10px;
  text-align: left;
  display: inline-block;
  vertical-align: top;
}

.cell:nth-child(1) {
  width: 90px;
}

.cell:nth-child(2) {
  width: 300px;
}

.cell:nth-child(3) {
  width: 300px;
}

.cell:nth-child(4) {
  width: 75px;
}

.cell:nth-child(5) {
  width: 200px;
}

.cell:nth-child(6),
.cell:nth-child(7),
.cell:nth-child(8),
.cell:nth-child(9),
.cell:nth-child(10),
.cell:nth-child(11),
.cell:nth-child(12) {
  width: 100px;
}

th {
  position: sticky;
  top: 0;
  padding-top: 5px;
  padding-bottom: 5px;
}
<div class="table">
  <div class="headers row">
    <div class="cell">A</div>
    <div class="cell">B</div>
    <div class="cell">C</div>
    <div class="cell">D</div>
    <div class="cell">E</div>
    <div class="cell">F</div>
    <div class="cell">G</div>
    <div class="cell">H</div>
    <div class="cell">I</div>
    <div class="cell">J</div>
    <div class="cell">K</div>
    <div class="cell">L</div>
    <div class="cell">M</div>
  </div>
  <div class="table-body">
    <div class="row">
      //more code here

While my intention is for this table to have overflow in both the x and y directions, I've noticed that when scrolling horizontally, the alternating gray rows don't remain visible.

If you have any insights or suggestions on what could be causing this issue, I would greatly appreciate your input!

Answer №1

Include the property display: table; in the .row class for optimal styling.

Differentiating between display:block; and display:table; in CSS.

For more details, check out this related discussion: CSS: display:block; vs display:table;

This information may provide valuable insights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Chrome is failing to run the keyframe animation transform

This solution seems to function properly on Firefox and Safari, and even on IE! However, it encounters issues when used on Chrome. (It runs smoothly on Firefox and IE, but on Chrome the animation does not display at all!) @keyframes animationFrames{ 0% ...

Differentiating row colors in an HTML table using ng-repeat

I am trying to color the rows of a table alternatively with green and yellow using ng-repeat. I initially attempted to do this without ng-repeat and it worked as expected. .table-striped>tbody>tr:nth-of-type(odd) { background: yellow ! ...

Tips for extracting value from a button inside a while loop in a modal

As I was working on my code, I encountered an issue with displaying pictures in a modal when a user clicks on a button. Here is the code snippet that I used to display the products and set up the session to store the selected picture for the modal. However ...

Issue with Jquery Animation Delay not executing as expected

I'm currently facing a challenge in delaying an animation. I've attempted both the Jquery attribute method and the setTimeout JavaScript approach, but unfortunately, neither has produced the desired outcome for me. The code is linked to a CSS ID ...

What is a simple way to make toggling a .click event more efficient

Currently working on my final project for my webpage development course, I am focusing on creating a blog-themed website. My goal is to implement a feature where clicking on a profile picture expands it into a box displaying a bio and additional informatio ...

Invoke JavaScript when the close button 'X' on the JQuery popup is clicked

I am implementing a Jquery pop up in my code: <script type="text/javascript"> function showAccessDialog() { var modal_dialog = $("#modal_dialog"); modal_dialog.dialog ( { title: "Access Lev ...

Achieving Right Alignment of Items in Navigation Bar using Bootstrap

I'm facing a challenge aligning elements to the right in my navbar using Bootstrap. Despite trying an external CSS file, I couldn't get the desired alignment. My goal is to keep the logo and brand name on the left while right-aligning the other i ...

Exploring the placement and animation of a Flexbox dropdown menu

I'm currently working on designing a header with three main elements: ---------- LOGO ---------- hidden navigation bar ---------- BUTTON ---------- This header layout is supposed to grow into the following structure: ---------- LOGO ------ ...

"Items within mui Grid do not properly align within the Grid container

I'm struggling to fit two large Grid items inside a Grid container. The Grid container needs to be 100% of the screen's height (or parent container) Grid items are large and need to fill the container while remaining scrollable Image #1 shows t ...

What could be the reason border-radius doesn't function properly on IE9, while it works fine on IE10 and Chrome?

Encountering an issue with IE9 where the border-radius property is not working in one div, while functioning perfectly in other divs. Browser Comparison: IE9 IE10, Chrome, FF Html Code: <article id="main-login"> <div class="radius-10 s ...

CSS animation for dynamic zoom in and out effect inspired by Apple's slideshow feature

I really love the smooth auto zoom in and out effect on this website: , especially for the banner images at the top. I tried to recreate it by inspecting the developer tools in my browser, but I'm having trouble implementing it as some properties are ...

What is the best way to ensure that this header remains adaptable to different screen

Looking for guidance on creating a fluid and responsive header design similar to the curved images shown at this link or this link. How can I ensure that my design maintains its shape without distortion when viewed on different devices? Any suggestions a ...

As the input field is modified, HTML transforms accordingly

I'm working on a registration form that requires some basic details. I want to dynamically change a question based on the user's input without having to submit the form first. For example, when the page loads the question might be, "Is Attendee ...

The ng-click functionality seems to be malfunctioning when used within the controller in conjunction with ng-bind

After coding, I noticed that my ng-click function is not working. When I inspected the element, I couldn't find ng-click displayed anywhere. Can someone please help me figure out what I'm doing wrong? var app = angular.module('myApp' ...

What is the difference between finding the XPath of immediate child text and all descendant text?

Looking to extract the top-level category from this structure: <ul class="categories"> <li>My top level category <ul> <li>my second level category</li> </ul> </li> </ul> ...

Troubleshooting problem with arrow in Bootstrap accordion

I'm currently developing an accordion feature, and I've encountered a problem where the arrow on the right side of each collapsed section is not visible, although it's still present. I suspect there might be some styling issues causing this ...

What is the method for adding a before pseudo-element to my button element?

HTML & CSS Issue <button>Get Postion</button> Below is the CSS code for styling a button: button { padding: 1rem; background-color: red; color: wheat; border: 4px solid yellowgreen; position: relative; cursor: pointer; ...

Creating a checkbox inside an anchor tag (<a>) element that triggers a function with ng-click

I am facing a scenario similar to this: <a ng-click="doSomething()"> Text <input type="checkbox"/> </a> Whenever I try to mark the checkbox, it triggers doSomething() function instead and the checkbox stays empty. I am aware that ...

The Bootstrap Library reference causes the anchor hover function to malfunction

Feeling frustrated after encountering an issue where the Bootstrap button class interferes with the hover function in standard CSS. Decided to create a custom solution by adding a grey box next to the button to display hover information instead of using t ...

Preserve the iframe src value in the dropdown menu even after the page is refreshed

I am trying to figure out how to prevent the iframe src from changing when I refresh the page, unless the user manually changes it using the dropdown menu with JavaScript. Can someone help me with this? <div class="row"> <div class="span9"> ...