Modify th:hover in CSS to alter the background color

I currently have a table structured as follows:

     <table class="cedvel">
            <caption>
                count:
                <%:Html.Encode(TempData["RowsCount"])%></caption>
     <thead>
                <tr>
                    <th id="thAfield1" class="field1,asc">
                        <span>field1</span><span id="spanAfield1" class="spanAscDesc">↑↓</span>
                    </th>
                    <th id="thfild2" class="field2,asc">
                        <span>field2</span> <span id="spanfield2" class="spanAscDesc">↑↓</span>
                    </th>
................................
     </thead>
            <tbody>
                <%if (Model.<----->.Count() > 0)
                  {
                      foreach (var abonent in Model.<---->)
                      {%>
                <tr>
                    <td>
                        data
                    </td>
                    <td>
                        data
                    </td>
................................
    </tr>
     <tr class="noData">
                    <td colspan="11">
                        no info
                    </td>
                </tr>
                <% }%>
            </tbody>
        </table>

My goal is to change the background color when hovering over th elements. I attempted to do so with CSS but was unable to achieve the desired effect. However, changing the background color on hover for tr elements worked perfectly.

table.cedvel th {
    background-color: #c3dde0;
    background-image: url(../Content/SiteImages/1.png);
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}
table.cedvel th:hover {
    background-color: Red;
}

My issue arose when attempting to set background-image to none during hover. The problem was that while the background color changed successfully, my image remained hidden.

Answer №2

table.cedvel th {
    background-color: #c3dde0;
    background-image: url(../Content/SiteImages/1.png);
}

table.cedvel th:hover {
    background-color: red;
    background-image: none;
}

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

Struggling with css margins and div image constraints, seeking guidance and tips for resolution

Struggling with creating a dynamic gallery that works smoothly in jsfiddle but encounters multiple issues when integrated into WordPress. The main problem is the excessive stretching of margins between image titles and meta-data, leading to misalignment an ...

What is causing this issue with the basic HTML and CSS code that is preventing it from displaying correctly

What does the HTML code look like? <html> <head> <title>Homepage</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"></div> </body> </html> ...

How to replicate a WordPress menu bar

Embarking on my coding journey, I've completed courses in HTML, PHP, CSS, JavaScript, and MySQL. Now, I've decided to dive into hands-on learning by creating a Wordpress child theme. My current challenge is figuring out how to overlay two differ ...

How to properly size a child div inside a parent container

I'm having trouble with sizing a child div inside a parent div. The problem is that the child div's size changes according to the number of elements it contains, but I want all the child divs to be the same size regardless. This issue arises with ...

What are the steps for incorporating a linear-gradient hue into a Slider?

Is it possible to apply a linear-gradient as color to Material-UI Slider? I have tried everything but can't seem to make it work. color: 'linear-gradient(180deg, #29ABE2 0%, #00EAA6 100%)' ...

Arrange four Divs next to each other with flexbox styling

I've been struggling with aligning my cards side by side. They are a series of divs nested in lists under a <ul> Changing the positioning is not resolving the issue, and I'm hesitant to alter the display as it's crucial for responsive ...

Could you please advise me on where I should apply line-height in order for it to work properly?

My div is structured like this: I am trying to decrease the spacing between the lines. I attempted adding a line-height attribute to both the parent div and one of the label elements like this: <div class="row" id="gadsDiv" runat=&q ...

How can you center a left floated div?

I am seeking to showcase a series of images in a horizontal layout on my page. Beneath each image, there are several links that need to be grouped together within a container. So far, I have tried placing them in floating divs, which align them to the lef ...

Styling your Kendo grid in ASP.NET MVC with custom CSS styling

I am facing a challenge with displaying two kendo grids side by side on a single view page. To modify the CSS style of a kendo grid using ASP.NET, I typically use: .HtmlAttributes(new { style="width:50%"}) However, when attempting to change more than one ...

Flexbox does not seem to be cooperating with CSS Auto Width

Hello Overflowers, I've designed an HTML page with the following specifications: 1. Resetting HTML, BODY, DIVs, and SPANs to have no border, padding, margin, or outline 2. Setting display properties for HTML, BODY, and DIV elements 3. Defining hei ...

The dropdown menu with Bootstrap's <li> sub menu is not expanding as expected

<li class="dropdown"> <a href="#" class="dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">Utilitas<span class="c ...

Why does everything seem to move in sync with the table's scrolling?

I recently had an issue resolved that fixed most of my concerns: I needed to make three separate edits, and now when I reintroduce the other two edits, they are included within the table section and scroll along with the table instead of being stuck beneat ...

The Radio button and Checkbox values are causing an issue where the Radio button is continuously summing upon clicking without a limit. Why is this happening? Check out

I'm currently stuck in a function and believe it would be helpful for you to guide me along the correct path. My goal is to sum the values of checked boxes with the values of checked radio buttons. However, the radio values are continuously accumulat ...

Using JQuery to apply a CSS class or check for a CSS class on multiple button elements that

Being new to Jquery and Javascript, I am facing challenges in understanding how to implement the following. Throughout my site, I use the same button class, and I am attempting to make Jquery apply a "clicked" class only to the button that was clicked, no ...

Using CSS to overlay text on an image on a webpage

Can anyone help me with this puzzling scenario? <TD><a href="index-1.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image20','','images/m21.jpg',1)">Home</a><img src="images/m2.jpg" nam ...

How to utilize Bootstrap 4's d-flex to make an element span the entirety of the available space?

Creating this specific design is now achievable with the new bootstrap d-flex feature. Can you guide me on how to craft a section similar to the one depicted in the second image? https://i.sstatic.net/LtTux.png https://i.sstatic.net/RlWvJ.png ...

Unusual alterations to HTML and CSS to meet specific needs

Struggling with bringing my website ideas to life! My header contains a navigation bar, followed by a centered chat box within a fixed <section>. Want the left and right side of the chat box to be content areas that scroll in sync while the chat box ...

Make the background disappear when the text field is left empty and the cursor is not present (onUnfocus)

When the text field is empty and there is no cursor in the text field, I want it to be transparent and for the spell checker not working. The result should be displayed a little to the left inside a <div>. Should this be done using CSS, JavaScript, ...

What is the best way to ensure a string of words in HTML/CSS wraps to the next line seamlessly?

As I work on creating my portfolio website using Bootstrap and custom CSS, I am running into an issue with the game titles breaking in the middle when displayed. Despite my limited proficiency in English, I tried searching for a solution without success. ...

Is there a way to automatically click the 'next' arrow on my image slider?

I'm currently working on a website that uses the Semplice theme in Wordpress. The built-in slider doesn't have an autoplay feature, so I attempted to use jQuery to automatically click the 'next' arrow every 5 seconds. However, I ran int ...