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

Choosing the subsequent div after the current one using Jquery

I am currently in the process of creating a drop-down menu button that, when clicked, reveals the previously hidden div underneath it. The code is functioning properly without the use of $(this).next, but it is displaying all divs with the class .menudrop ...

When the label is clicked, the radio button does not have a selected value

I am experiencing some strange behavior with a radio button, as shown in the attached GIF. Whenever I click on the label, the selected value disappears and the radio buttons become unchecked. I have been unable to identify the cause of this issue. I am ...

Guide on validating an Australian phone number with the HTML pattern

When it comes to PHP, I have found it quite simple to validate Australian phone numbers from input using PHP Regex. Here is the regex pattern I am currently using: /^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ | ...

Tips for achieving horizontal alignment of headers

My webpage has two headers positioned as 'CompanyName' on the top left and 'Date' at the top middle but I am struggling to align them horizontally. I attempted to enclose them inside a div element, however, this did not work. Can someon ...

Overlap of Navigation Bar and Carousel

Encountering an issue. I recently made a modification to my website in hopes of integrating a full-width carousel instead of a jumbotron. However, there seems to be a problem as my navbar is overlapping the jumbotron section along with the caption and oth ...

Customize the CSS styling of third-party components in different pages using NextJS

When working with third-party components, you can include their styles by importing their stylesheet into your component or _app.tsx file. For detailed instructions on how to do this, you can refer to Next.js documentation. Another option is to add the sty ...

What steps can be taken to modify the style of a single button belonging to a broader group of elements?

Is there a way to hide the save button within a Vue Modal without affecting other buttons with the same class? .btn.btn-primary { display: none; } Simply targeting .btn-primary in the CSS affects all elements with that class, and adding .modal woul ...

"Enhancing user interaction with Vue.js through the stunning ripple effect on

Is there a way to customize the ripple effect from this source so that it doesn't always have to be a DIV? Here's an example: Currently, when I implement it like this: <ripple class="btn">send</ripple> It works as expected, but as ...

Transforming the input button into images

I'm new to JavaScript and I'm looking to change the show button and hide button to images instead. The show button image should be different from the hide button image. Can anyone guide me on how to achieve this? Click here for reference $( ...

Setting an Element's attribute is only visible in the console

Just dipping my toes into the world of Web Development. While playing around with some JavaScript within HTML, I decided to try updating the content of an element. Upon running the code below, "Updated Content" appears in the console as intended. However, ...

The script is not functioning properly when placed outside of the HTML body tag

I have a main template that is functioning properly with the layout I've included here. However, I am facing an issue when trying to organize the scripts within one block. Specifically, when I move one of the scripts from the body section to the head ...

I created some jQuery code that modifies a button when it is hovered over, however, I ended up writing the code individually for each button. What steps can I take to turn it

Is there a way to turn the code for each button on my website into a jQuery function that can be applied to any button? This is how the code currently appears: $(document).ready(function() { $("#linkXML").hover( function() { ...

The attempt to unserializing the configuration schema in Yii2 was unsuccessful

My brain feels scrambled... I am attempting to insert an image in HTML within Yii2. I retrieve it from the database and place it into the view file, but when I try to display it using HTML tags, an error is thrown. However, the image is being added perf ...

Learning how to track mouse wheel scrolling using jQuery

Is there a way to track mouse scrolling using jquery or javascript? I want the initial value to be 0 and increment by 1 when scrolling down and decrement by 1 when scrolling up. The value should always be positive. For example, if I scroll down twice, the ...

What specific @media query should be used to target Windows Phone 8+ with high resolution?

As per the insights shared in Brett Jankord's article on Cross Browser Retina/High Resolution Media Queries The information suggests that Windows 8 phones do not adhere to device-pixel-ratio media queries. Are there alternative methods to target W ...

Acquire Table Element Using Javascript

I have a HTML table that contains information such as names, addresses, and phone numbers. Within each row of the table, there is a link that can be clicked to open a popover. When a popover is opened, I want to save the name from that particular row. The ...

Seeking assistance with changing the pages

Looking for assistance with troubleshooting my function. All variables are accounted for. var swith = document.getElementById("sub"); var one = document.getElementById("rule"); var two = document.getElementById("cool"); var three = document.getElementByI ...

What is the process for detaching and attaching click animations using the on() method?

I am encountering an issue with a recursive loop that executes a simple animation. These animations are controlled by the page load and clicking on controls .carousel_item. Click here for live sample JSFiddles for demonstration purposes Challenge: The pr ...

Steps for inserting a video into a new div upon selecting a hyperlink

Looking for a way to link menu elements to corresponding videos in adjacent divs? I have two divs set up - one with the menu list and another right next to it where the videos should be loaded. Forms seem like a potential solution, but I lack expertise i ...

Guide to positioning an image absolutely within a div

I am struggling to position a small close image within a div without success. The goal is for the image to always appear on the left side of the div, regardless of the content. The content consists of a text label with a maximum length of 8 characters. Iss ...