Resizable dynamic table in HTML

I am currently developing a flex table in HTML, constructed of multiple div elements. My goal is to make it resizable without using the traditional table tag. The layout of my table is similar to the one showcased in the following link. How can I achieve this using div elements exclusively?

<div class="container">
  <h2>Resizable Columns</h2>
  <table class="table table-bordered" data-resizable-columns-id="demo-table-v2">
    <thead>
      <tr>
        <th data-resizable-column-id="nr">#</th>
        <th data-resizable-column-id="first_name">First Name</th>
        <th data-resizable-column-id="nickname">Nickname</th>
        <th data-resizable-column-id="last_name">Last Name</th>
        <th data-resizable-column-id="username" id="username-column">Username</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>Mark</td>
        <td>Dude Meister</td>
        <td>Otto</td>
        <td>@mdo</td>
      </tr>
      <tr>
        <td>2</td>
        <td>Jacob</td>
        <td>Barney von Matterhorn</td>
        <td>Thornton</td>
        <td>@fat</td>
      </tr>
      <tr>
        <td>3</td>
        <td colspan="2">Larry the Bird</td>
        <td>What</td>
        <td>@twitter</td>
      </tr>
    </tbody>
  </table>
  </diu>

Explore the sample here for guidance.

Answer №1

Check out this neat solution:

*{
  box-sizing:border-box; margin:0; padding:0;
}
html,body{
  width:100%; height:100%;
}
body{
  background:#ccc; padding:7px;
}
.container>h2{
  background:#000; color:#fff; padding:3px 10px;
}
.flex{
  background:#fff; font-size:16px; display:flex; flex-wrap:wrap; justify-content:center; align-items:stretch;
}
.flex>div{
  display:flex; border:1px solid #000; width:calc(25% - 5px); justify-content:center; align-items:center; text-align:center; border-top:0; border-left:0; padding:3px 5px;
}
.flex>div:nth-child(5n+1){
  width:20px; border-left:1px solid #000;
}
.flex>div:first-child,.flex>div:first-child+div,.flex>div:first-child+div+div,.flex>div:first-child+div+div+div,.flex>div:first-child+div+div+div+div{
  font-weight:bold; border-top:1px solid #000;
}
<div class='container'>
  <h2>Resizable Columns</h2>
  <div class='flex'>
    <div>#</div>
    <div>First Name</div>
    <div>Nickname</div>
    <div>Last Name</div>
    <div>Username</div>
    <div>1</div>
    <div>Mark</div>
    <div>Dude Meister</div>
    <div>Otto</div>
    <div>@mdo</div>
    <div>2</div>
    <div>Jacob</div>
    <div>Barney von Matterhorn</div>
    <div>Thornton</div>
    <div>@fat</div>
    <div>3</div>
    <div>Larry the Bird</div>
    <div></div>
    <div>What</div>
    <div>@twitter</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

The max-width CSS property is failing to function properly on a specific DIV element

I'm having trouble restricting the size of the user-selected image with CSS. Can someone point me in the right direction? Currently, when a user selects an image, it is displayed at full size which sometimes extends beyond the visible area of the web ...

How can we send a JSONArray through a dynamically generated button event and then retrieve the elements of the JSONArray?

In the following SCRIPT code snippet: var jsonArr = [ { " name": "John", "age": 31, "city": "New York" }, { "name": "Smith", "age": 25, "city": "Dubai" } ]; function create() { createButton(jsonArr); } function cre ...

What is the best way to pass properties of a class instance to the super constructor of its parent?

Is there a way to transfer properties from a class to the parent's super constructor? ActionLog serves as the base class and is instantiated within a method in ActionRequestAccess ActionRequestAccess.ts export class ActionRequestAccess extends Actio ...

CSS clearfix doesn't appear to be functioning properly

I've been experimenting with using clearfix instead of the clear both property, but it's not working as expected. Despite following tutorials, the issue persists. How can I troubleshoot this and make it function properly? * { marg ...

CSS Hack: Changing a Single Value with HSL Color Palette

Can specific values be adjusted using hsl? Such as changing saturation or lightness while keeping the hue constant? .red { background-color: #ff0000; /* or, hsl(0,100%,50%); */ } .red-dark { // Increase saturation by +10% and decrease lightness by - ...

Selenium can locate an element by its CSS selector that comes after a specific element

How can I locate the text "Interesting" which is the first occurrence of the class b after h1.important when using Selenium? <div class="a"> <div class="b">Not interesting</div> </div> <div class="title"> <h1 c ...

Failure to display a base64 image retrieved from an asynchronous AJAX request

I am attempting to make multiple asynchronous ajax calls, one of which is to request a base64 image from the server. The strange thing is that it works perfectly in IE, Chrome, and Firefox when I set the ajax request for the base64 image to synchronous. Ho ...

Make sure the "Position Sticky" property has the same impact on nested children elements as

One method I am exploring to enhance the visibility of headers in blog posts involves utilizing position:sticky on the header. This way, header elements like H1, H2, H3, etc., can remain fixed at the top of the page regardless of scrolling. The issue arise ...

Incapable of composing text using the MUI SearchBar

I'm having trouble with my Material UI search bar - it's not letting me type anything into it. How can I resolve this issue? Despite trying the suggested code snippets from other answers, I keep encountering errors when integrating them into my ...

Reload the text content of a locally hosted webpage within an iframe at regular intervals

I have set up a simple webpage on my local machine to showcase the contents of some text files on a dedicated monitor. However, I am facing an issue where refreshing the entire webpage causes flickering. My goal is to only refresh the iframes and reload t ...

Incorporating Selenium Python to display text results in a single-line format for enhanced output presentation

Looking for a way to extract data from the following HTML code: <div class="main"> <div class="firstdigitinside"> <span class="firstdigit"> <span class="firstdigithere>1 ...

displaying a confirmation using jQuery in CodeIgniter

Hello everyone, I am a beginner in CodeIgniter and I am seeking assistance. I am attempting to create a confirmation message (div id="delmsg") using jQuery when deleting a record from MySQL database. The delete operation is functioning properly, but the me ...

What is the process to obtain the child theme URL in WordPress?

Currently, I am working on creating a child theme for my WordPress website. I have successfully uploaded the assets folder which contains both CSS and JavaScript files. This child theme will be completely customized to suit my needs. Within the <head&g ...

Exploring label-value pairs and extracting values using Jquery

Looking for labels with partially matching strings in order to find associated values is my current task. Below is a snippet of the source code: <dt> Loose Ones </dt> <dd> 8.00 </dd> <dt> ...

Having trouble adding an image link to the navbar using bootstrap?

I am experiencing an issue where the image in the provided code is not displaying. Interestingly, when I remove the alt attribute, it shows up as a broken link. This problem persists even when I try using different images or links to images. As someone wh ...

Seeking a proficient Cloud Code specialist skilled in JavaScript, focused on managing installations and channels

My experience with Javascript is limited, but as I work on my application, I realize the necessity of incorporating it into Cloud Code. I have a Parse class called Groups where I store group data including Name, Description, Users, and Requests. Name, Des ...

Can a CSS class be added to a form_row in Symfony 4 Twig?

Need help with adding a CSS class to the entire form_row in a Symfony 4 twig template! Currently, my code only adds the class to the input tag, but I require it to be added to the parent div container. Here is the current code snippet: {{ form_ ...

Tips for closing two nested Material-UI popovers when a button is clicked or when clicked elsewhere

Trying to create a menu with nested popovers from Material-ui has presented a challenge. I want all the popovers to close when I click on a menu option, rather than having to close them individually. Additionally, it would be more user-friendly if the popo ...

How can I create a basic jQuery validation that only applies to the border and background without affecting the text?

I have been on a lengthy quest to find the simplest way to implement jQuery validation - essentially changing border color and background. No frills, just the basics! Many methods I've come across seem to involve a lot of code. Take this snippet as a ...

Exploring Javascript's Standard Object: A Guide to Retrieving Two Elements

If I have a special data object: var data = []; data["Name"] = ["Janet", "James", "Jean", "Joe", "John"]; data["Number"] = [25, 22, 37, 19, 40]; Let's say I'm looking for the minimum number value, which is '19' in this case. How ...