Is there a way to design a table that is responsive and automatically converts to a list when viewed on a mobile device

I am trying to design a responsive table showcasing artists' names. The goal is to have it look similar to this example:

After finding and customizing code for the table, I encountered an issue when the table collapses on mobile view. The invisible elements are still taking up space, causing gaps in the list of names: View issue here: https://codepen.io/alanvkarlik/pen/GReVOjV (Note: Borders around cells will be removed in the final version)

The code may seem complex, but I am unsure how to address this issue.

In Desktop view, I aim to separate each row with artist names using ✧ symbols, as seen on

/* Page styling
    ================================== */

html {
  height: 100%;
  background-color: #EEE;
}

body {
  box-sizing: border-box;
  min-height: 100%;
  margin: 0 auto;
  padding: 2em;
  max-width: 800px;
  font-size: 1.2em;
  background-color: white;
  text-align: center;
}


/* Tables
    ================================== */

.Rtable {
  display: flex;
  flex-wrap: wrap;
  margin: 0 0 3em 0;
  padding: 0;
  position: relative;
  top: 3px;
  left: 3px;
}

.Rtable-cell {
  box-sizing: border-box;
  flex-grow: 1;
  width: 100%;
  padding: 4px;
  overflow: hidden;
  list-style: none;
  border: solid 3px white;
  background: rgba(112, 128, 144, 0.2);
}

.Rtable-cell-gap {
  border: solid 3px white;
  background: rgba(112, 128, 144, 0.2);
}

.Rtable-cell,
.Rtable-cell-gap {
  margin: -3px 0 0 -3px;
  background-color: white;
  border-color: #e2e6e9;
}


/* Table column sizing
    ================================== */

.Rtable--5cols>.Rtable-cell {
  width: 30%;
}

.Rtable--5cols>.Rtable-cell-gap {
  width: 5%;
}


/* Responsive
    ===========...

Answer №1

Having HTML elements in the DOM solely for decorative purposes can be quite uncomfortable.

Using a table for layout can introduce unnecessary semantics.

One alternative approach is to utilize a CSS grid with 3 columns for wider viewports and 1 column for narrower ones.

The stars can then be dynamically added outside the DOM by using absolute positioning pseudo elements.

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 2em;
}

.container>div {
  position: relative;
  text-align: center;
}

.container>div:not(:nth-child(3n-2))::after {
  position: absolute;
  content: '✧';
  top: 100%;
  left: 0;
}

.container>div:last-child::after,
.container>div:nth-last-child(2)::after {
  display: none;
}

@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
  }
  .container>div::after {
    display: none;
  }
}
<div class="container">
  <div>name</div>
  <div>name</div>
  <div>name</div>
  <div>name</div>
  <div>name</div>
  <div>name</div>
  <div>name</div>
  <div>name</div>
  <div>name</div>
</div>

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

Moving elements upwards and downwards using CSS transitions

I am currently designing a metro tiles menu for my website, without using JavaScript and only relying on HTML and CSS. The issue I am facing involves the sliding tiles and the direction in which they slide. Additionally, there seems to be a problem where ...

Utilize CSS to ensure that the hover effect of the main navigation remains active even when the mouse hovers over the sub-menu

Is there a way to make the hover state in navigation items persist when the mouse hovers over a sub-menu? Currently, when hovering over a top-level nav item, the link color changes to white and background turns black, but this reverts back once the mouse m ...

Is your navigation bar failing to extend to the entire width of the page

Click Here for the Host Folder If you follow the link and then click on "all.html," you will come across a page with an incomplete navbar. The li elements in the list appear to be stacking oddly, causing "Member Resources" and others to show up in a row b ...

Creating a well-structured HTML layout following the BEM Methodology

I'm unsure about this HTML structure. Does it follow the BEM approach correctly? <div class="boxWithBorder"> <div class="header"> <h2 class="boxWithBorder__element"></h2> </div> </div> In my opinion, it sh ...

My JavaScript/jQuery code isn't functioning properly - is there a restriction on the number of api calls that can be made on

Below is the code I have implemented from jquery ui tabs: <script> $(function(){ // Tabs $('#tabs1').tabs(); $('#tabs2').tabs(); $('#tabs3').tabs(); //hover states on the sta ...

Use CSS to configure the mouse wheel for horizontal scrolling

Looking to create a horizontal page layout, but when I scroll with the mouse wheel the content only moves vertically. Is there a way to enable horizontal scrolling using the mouse wheel? Does CSS have a property for this? For instance, is there something ...

Is it possible to automatically extract HTML code from a webpage using a function, without having to do it manually?

Is there a way to fetch the HTML code of a website after running a particular function? Here's the scenario I'm dealing with: I need to extract the link of a source embedded in an iFrame element that only becomes visible when I execute a specif ...

Error in JavaScript: Uncaught TypeError - Unable to access the "left" property of an undefined object

This error is really frustrating and I've come across several inquiries regarding this console issue. It's not providing enough information in the chrome console for me to effectively troubleshoot. /** * Adjustment of dropdown menu positio ...

The Google map is not appearing when placed within the "row" class

My goal is to showcase Google Maps on my website, and every time I try to do so using the following code: <div class="large-12 columns" id="map-canvas"></div> The map displays perfectly and works as expected. However, when I nest this div wi ...

"Why is it that only one of the two similar spans with onclick event is not functioning properly

Encountering a perplexing issue that has me stumped. Here's the code in question: js: function Test() { alert("test"); } html: <span id='bla' onclick='Test()'> Click me </span> <hr> <span id='bla2& ...

Retrieve data quickly and navigate directly to specified div element on page

I am facing an issue with scrolling on my website. While it currently works fine, I would like to make the scrolling instant without any animation. I want the page to refresh and remain in the same position as before, without automatically scrolling to a s ...

Creating a basic popup with jQuery: A step-by-step guide

Currently in the process of creating a webpage. Wondering how to create a popup window with an email label and text box when clicking on the mail div? ...

Combining two PHP includes within a single HTML file

As I delve into web development, an interesting issue has arisen: I have a single HTML file with two PHP includes. Strangely, only the first include is working while the second one seems to halt the transfer of HTML code to the browser. There are no errors ...

Using a custom font in a Django project without relying on the Google Fonts API

I've hit a roadblock in my programming journey and I'm seeking help. As a newcomer to both programming and Django, I've been following a helpful tutorial up until part 4. Everything was going well until I stumbled upon a new font online cal ...

Dynamic visual content (map)

I'm currently working on creating an interactive image for my website where clicking on points A, B, C, ... N will reveal bubbles with images and text inside them. Would anyone be able to provide guidance on how to achieve this? Or direct me to resou ...

Text that only occupies a portion of the screen width

My unordered list (ul) contains three list items (li). The first li element displays the text "opptakskrav" and the last li element displays "ja". Can anyone explain why the text in my second li element does not use the full width and starts a new line hal ...

What is the technical process behind conducting A/B testing at Optimizely?

I'm currently experimenting with Google Analytics and Content Experiments for A/B testing on my website, but I'm encountering some challenges in making it seamless. To utilize the Google API properly, a few steps need to be taken. Firstly, I nee ...

Using Vue3 to conditionally display a child div based on the class of its parent div

Just starting out with Vue, I'm currently experimenting with the active classes feature from this Vue3 carousel plugin. My goal is to only show the text and link divs for the carousel__slide--active class, but at the moment, all carousel__items are di ...

What could be causing my <UL> to not properly expand around the <LI> items inside of it?

I am currently working with WordPress and have created a menu using a list structure. Here is an example of how it looks: <ul> <li>Home</li> <li>About</li> <li>ParentItem <ul> <--- The heig ...

Can you restrict the selection of text to only the current element?

<div class="container"> <div class="item1">text text text in div element 1</div> <div class="item2">text text text in div element 2</div> </div> Is there a way using HTML nodes, CSS, or JavaScript to restrict the select ...