Is there a way to set an absolute placement for <tr> tags within a <table> using Html and Css?

Struggling to position the rows in my table vertically for CSS animations. I'm having difficulty ensuring the correct width for the rows.

Here's what I have so far:

<!DOCTYPE html>
<html>

<head>
  <style>
    table {
      border: solid 1px;
      width: 100%;
    }

    tbody {
      position: relative;
      display: block;
      height: 96px;
      border: 1px dashed;
      width: 100%;
      left:0;
      right:0;
    }

    tr.absrow {
      position: absolute;
      width: 100%;
      left: 0;
      right: 0;
      border: dotted 1px;
    }

    td {
      border: solid 1px;
      border-collapse: collapse;
    }
  </style>
</head>

<body>
  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Age</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr class="absrow" style="top: 0px;">
        <td>John</td>
        <td>25</td>
        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6aca9aea886a3bea7abb6aaa3e8a5a9ab">[email protected]</a></td>
      </tr>
      <tr class="absrow" style="top: 32px;">
        <td>Alice</td>
        <td>23</td>
        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51303d383234113429303c213d347f323e3c">[email protected]</a></td>
      </tr>
      <tr class="absrow" style="top: 64px;">
        <td>Bob</td>
        <td>29</td>
        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62000d0022071a030f120e074c010d0f">[email protected]</a></td>
      </tr>
    </tbody>
  </table>
</body>

</html>

The issue: while the vertical positions seem correct, the columns are not evenly sized and the rows don't span the table's full width.

What are my options? Do I need to manually set column widths or can I rely on automatic sizing by the browser like a regular table? How can I make the rows span the full width?

EDIT:

I tried using a list styled as a table, but it was not helpful. The user couldn't track the moving rows easily, resulting in jittery and lagging animations. Instead, I decided to implement a table sorting feature when the user clicks a button.

Answer №1

It is unclear why you would need to utilize position: absolute for animation purposes. However, if you find it necessary to use position: absolute, then your sole choice is to define the width for each column and ensure that the total widths amount to 100%

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

Can a jQuery/JavaScript script be run standalone?

I've got a bunch of HTML pages saved on my computer and I'm looking to create a JavaScript script that can extract specific text or elements from those pages. I found some jQuery code snippets on Stack Overflow that do what I need, but I'm n ...

What is the method for displaying a div adjacent to a password input field?

I am attempting to display a password verification box next to an input field. The current logic is functioning properly, but the box containing all password requirements is not appearing in the correct position. Instead of being positioned adjacent to the ...

How can HTML and CSS be linked to display images independently?

Check out this code: body{ background-image:url('http://wallpoper.com/images/00/31/33/51/black-background_00313351.jpg'); } div.header{ background-color:#F0F8FF; text-align:center; padding:3px; ...

Display a hidden div only when a cookie is set during the initial visit

I'm currently facing an issue while trying to set multiple cookies based on the existence of a div using JavaScript. On the first visit, I want to display the div to the user if it exists, then set a cookie (named redCookie) that expires in 3 days. Up ...

Implement automatic data replacement using PHP and MySQL triggers

The code provided below pertains to postar.php file include "conexao.php"; $consulta = mysqli_query($conexao, "SELECT titus.titus, titus.des, titus.link from titus"); while($postagem = mysqli_fetch_object($consulta)); echo "<d ...

Utilize ASP.Net to Retrieve and Showcase RSS Feeds

Looking to read and display a specific feed on my website. Developed in C# using .NET 2. Attempted to follow this tutorial: Encountered the following error: A column named 'link' already belongs to this DataTable: cannot set a nested table n ...

Focus on selecting the first child <li> element that contains an <a> tag within it

Struggling a bit with selecting only the first child within a li tag that contains a link. HTML: <ul class="dropdown-menu" role="menu" aria-expanded="true"> <li role="presentation" class="dropdown-header">Label</li> <li><a ...

When using Italics, the conflict arises between the specified line-height and the actual height of the

Recently, I encountered an issue that has me a bit perplexed: I have a span element with line-height set to 18px and font-size at 16px. Everything works perfectly when the text inside is regular; the height of the span remains at 18 pixels. The problem a ...

Apply the active class to only one element at a time

Presented here is a table showcasing available dates and times. Users can select a specific time by clicking on the "Choose" link. Currently, when a user selects a time, the class "active" is applied. However, the desired behavior is to remove the previous ...

Can you assist in resolving this logical problem?

exampleDEMO The code above the link demonstrates how to control input forms based on a button group selection. In this scenario, when a value is inputted on the 'First' Button's side, all input forms with the same name as the button group ...

Creating a blurred background effect when a React portal is presented

I have implemented React portals to display a modal popup after the form is submitted. However, I am facing an issue with blurring only the background while showing the modal, similar to what is shown in picture 2. Initially, I tried using document.body.st ...

Dynamic Column Image and Text Display

I am working on a website where I am trying to have an image on the left and a paragraph on the right, but when the screen size is reduced, I need the layout to switch so that the image is at the top and the paragraph is at the bottom. Even though I have ...

Modifying the CSS design of specific columns within a table created using JavaScript

A unique way to showcase JSON data in a table is by utilizing a for loop within a function. This method, however, does not assign an ID or Class to the table. To hide the final three columns of this table using CSS, the following code can be employed (whe ...

Having trouble with my PHP index not properly redirecting to the dashboard file after logging in

I have created a login form and implemented some functionalities. One of the key features is redirecting to the dashboard file after successful password validation. I attempted to troubleshoot using chatgpt, but the issue persists. I am reaching out for as ...

What could be the reason for the hover attribute not functioning properly in NextJS

Why isn't my CSS recognizing the hover attribute? Here is my code: I would like the class "mega" to appear when hovering over the li tag. <nav className="mobile-hide"> <ul className="flex-item second-links&quo ...

How come jQuery won't let me activate the 'change' event on a radio button?

Click the link below to access the page: Below are the original javascript codes that are functioning correctly: $(document).ready(function(){ $(".open_gene").on('change', function(event) { $('#Gene_field').show(); }); ...

Is it possible for me to utilize the functionality of the "for" attribute in the label?

After searching extensively online with no luck, I found myself wondering if anyone is aware of a resource similar to the one provided by caniuse.com that outlines browser support for the for attribute within a label tag? I am specifically interested in t ...

Connecting with a php anchor and hash symbol in a website URL

Looking to include a PHP anchor along with a hash anchor in an HTML link. <?php echo '<a href="test.php?page='.$i.'#hash">'.$i.'</a>'; ?> The PHP code successfully echoes the link, but upon clicking it, th ...

Coding in PHP, JavaScript, and HTML allows builders

I am facing some difficulties in locating my specific question, so I will describe it here. Currently, I am working with an oracle database and integrating it into an HTML website using javascript and php. I have successfully displayed the php file, but th ...

Steps to create a customized on-click effect for the search button

I have created the following: https://i.sstatic.net/Eu9kh.png And I am aiming for this: https://i.sstatic.net/maKCM.png Both search bars have on-click states but I am struggling to achieve this using bootstrap, CSS, JS. Can someone guide me on how to ...