Highlighting table rows on mouseover using CSS

I am trying to add a hover effect to my table rows, but when I apply the CSS styles for this behavior, the rows start wrapping. Here's a comparison of how the table rows look before and after applying the styles. You can see the wrapping issue in the screenshot labeled after.

Is there a solution to prevent the table rows from wrapping?

.table_class tr {
  display: inline-block;
  vertical-align: middle;
  -webkit-transform: perspective(1px) translateZ(0);
  transform: perspective(1px) translateZ(0);
  box-shadow: 0 0 1px transparent;
  background: #2098D1;
  -webkit-transition-property: color;
  transition-property: color;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
}

.table_class tr:before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: #e1e1e1;
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
  -webkit-transform-origin: 100%;
  transform-origin: 100%;
  -webkit-transition-property: transform;
  transition-property: transform;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-timing-function: ease-out;
  transition-timing-function: ease-out;
}

.table_class tr:hover,
.table_class tr:focus,
.table_class tr:active {
  color: white;
}

.table_class tr:hover:before,
.table_class tr:focus:before,
.table_class tr:active:before {
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
}
<div class="col-md-9">

  <div class="row">
    <!-- TOP -->
    <table class="table table-bordered table_class">
      <tbody>
        <thead>
          <tr>
            <th colspan="2" class="child_meaning">Meaning of Aadi</th>
          </tr>
        </thead>
        <tr>
          <td>Name : </td>
          <td>Aadi</td>
        </tr>
        <tr>
          <td>Meaning : </td>
          <td>Adornment, Beginning, Perfect, Most important, Ornament, Unequalled</td>
        </tr>
        <tr>
          <td>Gender : </td>
          <td>Boy</td>
        </tr>
        <tr>
          <td>Numerology : </td>
          <td>6</td>
        </tr>
        <tr>
          <td>Syllables : </td>
          <td>2</td>
        </tr>
        <tr>
          <td>Religion : </td>
          <td>Hindu</td>
        </tr>
        <tr>
          <td>Rashi : </td>
          <td>Mesha</td>
        </tr>
        <tr>
          <td>Nakshatra : </td>
          <td>Krithika</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

Answer №1

After reviewing your screenshots, it appears that the problem arises when your table rows start to wrap upon implementing the hover state. This issue occurs because you have specified display: inline-block for your <tr> elements. To resolve this, you can adjust the display property to something that will prevent your rows from becoming inline elements. Here is an example solution:

.table_class tbody>tr {
  display: block;
  vertical-align: middle;
  -webkit-transform: perspective(1px) translateZ(0);
  transform: perspective(1px) translateZ(0);
  box-shadow: 0 0 1px transparent;
  background: #2098D1;
  -webkit-transition-property: color;
  transition-property: color;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
}

.table_class tbody>tr:before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: #e1e1e1;
  -webkit-transform: scaleX(1);
  transform: scaleX(1);
  -webkit-transform-origin: 100%;
  transform-origin: 100%;
  -webkit-transition-property: transform;
  transition-property: transform;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-timing-function: ease-out;
  transition-timing-function: ease-out;
}

.table_class tbody>tr:hover,
.table_class tbody>tr:focus,
.table_class tbody>tr:active {
  color: white;
}

.table_class tbody>tr:hover:before,
.table_class tbody>tr:focus:before,
.table_class tbody>tr:active:before {
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
}
<div class="col-md-9">

  <div class="row">
    <!-- TOP -->
    <table class="table table-bordered table_class">
      <tbody>
        <thead>
          <tr>
            <th colspan="2" class="child_meaning">Meaning of Aadi</th>
          </tr>
        </thead>
        <tr>
          <td>Name : </td>
          <td>Aadi</td>
        </tr>
        <tr>
          <td>Meaning : </td>
          <td>Adornment, Beginning, Perfect, Most important, Ornament, Unequalled</td>
        </tr>
        <tr>
          <td>Gender : </td>
          <td>Boy</td>
        </tr>
        <tr>
          <td>Numerology : </td>
          <td>6</td>
        </tr>
        <tr>
          <td>Syllables : </td>
          <td>2</td>
        </tr>
        <tr>
          <td>Religion : </td>
          <td>Hindu</td>
        </tr>
        <tr>
          <td>Rashi : </td>
          <td>Mesha</td>
        </tr>
        <tr>
          <td>Nakshatra : </td>
          <td>Krithika</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

I hope this solution resolves your issue. Additionally, I have scoped your row styles so that they only apply to the table body and not the header.

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

Angular 12 experiencing CSS alignment issues

In my Angular component, I have the following CSS: .folders { border-left: 5px solid #b8744f; -moz-border-radius: 5px; -webkit-border-radius: 5px; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff; /*CORRECTION NEEDED ...

Minimizing the menu bar while scrolling down (bootstrap3)

Could anyone help me with creating a navigation-bar effect similar to the one seen on ? I want the bar to shrink and the logo to change after scrolling down my page. My website is built using bootstrap 3. Is there a simple way to achieve this effect with ...

Can we implement a variety of site designs based on the size of the window?

Utilizing media queries allows us to modify the CSS for various screen sizes. My inquiry is: can we switch to a completely different page layout (or View in MVC) when the window size, specifically when the width is less than 500? Assuming that the control ...

Ways to showcase information from an angular service

I'm struggling with displaying data from a service in my HTML view using AngularJS. My goal is to show a list of submitted forms called Occurrences in the view. When clicking on a list item, I want to be able to view all the data fields submitted thro ...

Creating a Three-Row Table with Material-UI and React

I am looking to achieve a layout similar to the one shown in the image below: I want to construct a table with three rows, where the third row is positioned below the first and second rows, and the width of the third row is equal to the combined width of t ...

Is there a way to transfer table row data to another table by simply clicking on the corresponding checkbox in the same row?

I'm working with a table that includes 4 fields: service, amount, tax, and action. My challenge is to have the data from any row in the first table added to a second table when its checkbox is selected. The second table should have the same fields a ...

The relationship between elements and text input positioning

I am faced with a unique challenge. As a user types in an input field, I need to display a reset button positioned center right of the input. I must adhere to the current HTML structure for the label, input, button, and error message and I prefer not to r ...

Show data based on the chosen destination

Recently, I've been working on creating a simple printer manager to monitor the status of all my printers. Although I have successfully displayed all the data, I'm facing an issue while trying to organize it by location. The error message I keep ...

Enhance the numerical value displayed in jQuery UI tooltips

I have folders with tooltips displaying text like '0 entries' or '5 entries' and so on. I am looking for a way to dynamically update this tooltip number every time an item is added to the folder. The initial count may not always start a ...

Unable to transfer card from the top position in the screen

Utilizing Tailwind (flowbite) for the frontend of my project, I encountered an issue where the Navbar was overlapping the Card. I attempted using mt-8 to resolve the problem, but it did not yield significant changes. What adjustments should I make to achi ...

Tips for transferring the ID from one element to another using JavaScript

I'm attempting to create a slideshow using icons all within one class. The "active" style class will have an ID and represent the current picture. By clicking either the left or right button, I aim to change the style of the active class. const l ...

The tab content in VerticalTab Material React UI is spilling out and overflowing

Having some trouble with this particular component. Whenever I input content larger than my Grid size, it overflows the VerticalTab section. You can see an example of this in this codesandbox. Here's what I've attempted: return ( <div cla ...

CSS: element misplaced at the top instead of the bottom where it belongs

The component with the ID of "#bottom-nav" actually appears at the top. I just designed this on CSS-board, so feel free to review the HTML and CSS code Take a look at it on CSS-desk here It is positioned at the very end of the page and includes a ' ...

Stop the background from scrolling and prevent auto-jumping to the top on mobile devices

When users click on the hamburger icon in the top right of our mobile site, I want the drop-down menu to appear and be scrollable without the background scrolling. I tried using JavaScript to set the body to fixed when the menu icon is clicked, but this ca ...

What could be the reason for the bottom edge of my central diagonal image having a darker border?

I can't figure out why the border on the bottom edge of my image is darker. You can check out the demo here. To get a closer look at the issue, you can open a software like GIMP and zoom in on the following image to see the difference in values: http ...

Which file extension is superior for SEO: .html, .php, or .aspx?

Which file extension is more SEO-friendly: .html, .php, or .aspx? Or is an extension-less URL the best option for SEO? ...

"Modifying the height of an SVG <g> element: A step-by

Is there a way to adjust the height of a g element? Trying to set the height using {params} but it's not responding I made some changes in the comments because the svg is quite large (Scene.js) {/* Transformation */} <g transform="trans ...

Implement Bootstrap and CSS to ensure that my content appears below the header when users scroll down

I am struggling with a simple HTML page that is working well with CSS, but encountering an issue where the input form gets placed above the header when scrolling down. I want the header to always remain above the content even while scrolling. Any suggesti ...

Transferring time for streaming MP3 files from server to HTML5 audio

Currently, my node.js server is set up to convert and stream mp3 files in real-time. I have integrated an HTML5 audio tag to play this stream, but I am encountering a problem - the audio element is unable to determine the duration of the mp3 until it has c ...

Ways to access the properties of an HTML element with JQuery

Can anyone tell me how to extract the value from a specific HTML element using JQuery? For example: <span id="45463_test"></span> (the proper tags need to be used for the code to work correctly) Specifically, I am looking to retrieve the va ...