Ways to remove the extra space above and below text within a td element

My goal is to make the background change when a user hovers over the td element. The current behavior of my code can be seen in the image below:

I am working to eliminate the white space so that the gradient fills the entire td/cell.

The following code snippet represents one row of my table.

    <tr>
        <td class="itemTrue">
            <h4>AMA<br>ROUND ALUMINUM MAST ARM SERIES</h4>
        </td>
        <td class="itemTrue">
            <h4>AVPL-SSA<br>4 INCH SQUARE STRAIGHT ALUMINUM SERIES</h4>
        </td>
        <td class="itemTrue">
            <h4>SMA<br>ROUND ALUMINUM MAST ARM SERIES</h4>
        </td>
        <td class="itemTrue">
            <h4>AVPL-SSS<br>4 INCH SQUARE STRAIGHT STEEL SERIES</h4>
        </td>
    </tr>

Below is the CSS code affecting these tags.

table {
  position: relative;
  top: 50px;
  box-shadow: 1px 1px 8px 7px #234229;
  width: 1300px;
  cell-spacing: 0px;
  padding: 0px;
}

table, td, tr {
  border: 1px solid black;
  font-family: 'Roboto Slab', serif;
  font-size: 12px;
  border-spacing: 0px;
  padding: 0px;
  line-height: 14px;
  vertical-align: baseline;
}

td {
  text-align: center;
  margin: 0px;
  padding: 0px;
}

#armPoles > td {
  border-bottom: 5px double black;
  margin: 0px;
}

.itemTrue :hover {
  color: white;
  background: #e4e4e4;
  background: -moz-linear-gradient(top,  #e4e4e4 0%, #295534 73%, #1d3923 88%, #000000 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#e4e4e4), color-stop(73%,#295534), color-stop(88%,#1d3923), color-stop(100%,#000000));
  background: -webkit-linear-gradient(top,  #e4e4e4 0%,#295534 73%,#1d3923 88%,#000000 100%);
  background: -o-linear-gradient(top,  #e4e4e4 0%,#295534 73%,#1d3923 88%,#000000 100%);
  background: -ms-linear-gradient(top,  #e4e4e4 0%,#295534 73%,#1d3923 88%,#000000 100%);
  background: linear-gradient(to bottom,  #e4e4e4 0%,#295534 73%,#1d3923 88%,#000000 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e4e4e4', endColorstr='#000000',GradientType=0 );
}

h4 {
  font-weight: normal;
}

Answer №1

It appears that you are missing a tag for your H4 element, perhaps consider setting that as well. Additionally, utilizing different color backgrounds can assist you in identifying which tag may be causing the issue at hand.

Therefore, I recommend trying to add 'padding:0' and other relevant properties to your CSS code.

Answer №2

To add a gradient effect to your <h4> elements on hover, it's important to remove the default margin with h4 { margin: 0; }. Another option is to apply the hover effect directly to the td element itself: td:hover { background: blue; }

Answer №3

Simply including

td:hover {
  background: linear-gradient(...);
}

Answer №4

It completely slipped my mind that h4 elements can actually have margins, and once I set them up, the issue was resolved.

A huge thank you to all those who offered their assistance - much appreciated! =)

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

Adjust the width of the <li> element based on the quantity of its children

If the number of list items can be changed dynamically, how can I adjust the width of each item so that the total width is always 100%? Here is an example code snippet: <nav> <ul> <li>A</li> <li>B</li> &l ...

Nesting a DIV tag within another DIV tag

Being relatively new to web design, my understanding of the DIV tag is that it serves as a logical container for whatever content is inside, and those elements will be formatted according to its rules. I have an outer DIV tag styled as <div style="margi ...

What is the best way to center a single element perfectly between two other elements within a container that is positioned absolutely in the center of the window?

I need to create a markup that has the following structure: <div id="container"> <div id="left"> This is the main text. </div> <div id="center"> Hello! </div> <div id="right"> some content </div> ...

Avoid changing the button color to a lighter shade when it is clicked

Is there a way to prevent button text from changing to a lighter color after clicking? I am facing an issue where the button I set to red turns slightly whiteish after it is clicked. How can I ensure that the button stays red at all times? Header Toolbar ...

What causes the empty gap between the accordion title and its content in Bootstrap?

I'm currently working on a Bootstrap accordion and I've encountered a problem where a white line appears underneath the heading whenever I click to expand it. Here's the accordion Here's my current code snippet: HTML - All divs do clo ...

Position the right div to float to the right with a dynamic width ahead of the left div in HTML to achieve

This particular challenge has proven to be quite difficult for me, and I have a feeling that I am overlooking something simple. My goal is to create a layout with a fixed-width left sidebar and a responsive variable-width content section on the right. Th ...

Setting a restriction for a variable to show a maximum of 50 characters

Is there a way to restrict the anchor text displayed below to just 50 characters? echo '<td style="" class="pointlink"><span class="pointlink"><a href="http://'.$rowad["1site"].'">'.$rowad["1site"].'</a>< ...

JS: Ensure to scroll down once the div element has been "unhidden"

Within a div element, I have an abundance of content: <div id="x" class="unhidden"> text and additional divs </div> The CSS class 'unhidden' is defined as: display: block; Upon clicking a link, the element with the id='x& ...

When navigating to a subsite or subfolder, the SVG href ID cannot be located

The topic at hand revolves around another issue: The challenge of creating an Ajax website with links from multiple subfolders. Take a look at the discussion where a solution for that problem was discovered. However, my current dilemma with that solution ...

Menu manipulation: Shifting menus left and right with a click

Take a look at this link. There are 12 menu items, but only 4 are visible due to space constraint. The rest are hidden. Update: Jsfiddle cleaned up and removed my fiddle. I have provided an alternative link above. There was a missing jQuery part in my que ...

Is there a way to easily copy the content within the <code> tag to the clipboard?

I've attempted to use the following code, but unfortunately, it's not functioning properly. Is there a way for me to copy the contents inside the <code> tag to my clipboard? <pre id="myCode"> <code> console.lo ...

Struggling to position CSS div in the middle of computer screen

I have created a main login div that is always displayed in the middle of the screen. However, I also have two additional divs - one that is supposed to show above the login div and the other below it. While the login div displays perfectly in the middle ...

Utilizing JavaScript to retrieve input names from arrays

This is the HTML form that I am currently working with: <form action="#" method="post"> <table> <tr> <td><label>Product:<label> <input type="text" /></td> <td><label>Price:<label> ...

Emphasize entries in an index that match the currently visible content as you scroll

I have a table of contents in my HTML page with the CSS attribute position: fixed;. I want to emphasize the current reading position by highlighting it (bold or italics) as I scroll down the page. | yada yada yada ... 1. Secti ...

Is there a way to shift the button over to the left?

I am currently utilizing the modalExample provided in the Bootstrap documentation. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Open modal</button> <di ...

Tips for attaching functions to a fresh SVG element with jQuery?

My jQuery code creates an <svg> element and appends it to a <div>. When I try to access the appended <svg> using each() after the append() function, the event handler doesn't work. However, if I create the <svg> element before ...

What is the best way to reduce the font size on a

I've been applying the following CSS: .text_style3{ font:normal 8px Helvetica; color:#f7922c; } I'm trying to decrease the size further, but anything below 10px doesn't seem to work. I've attempted using 7px, 6px, 5px, etc., w ...

Converting data from an HTML file to JSON with the help of <input file> feature in Javascript (Vue)

Currently, I am attempting to upload an HTM file using in Vue. Within this file, there is a styled table utilizing , and other HTML elements... I am curious, is it feasible to extract the tabulated data from the HTM file and convert it into another forma ...

Tips for changing a div's visibility with radio buttons in jQuery

$(':radio').change(function(event) { var id = $(this).data('id'); $('#' + id).addClass('none').siblings().removeClass('none'); }); .none { display: none; } <script src="https://ajax.googleapis.com/ ...

The exact measurement of width is not specified in the custom element that extends HTMLCanvasElement

I have created a custom element that extends a canvas, but when I try to add it to the DOM, the width appears to be undefined. Here is my code snippet. class Renderer extends HTMLCanvasElement { constructor() { super(); } } customElements.def ...