Modify the background color of an element when hovering using CSS

When I hover over a rectangle created with HTML and CSS, I want it to change color. However, my attempts at implementing this feature have been unsuccessful.

Here is the HTML code snippet:

<div id="teamspeak_box"><a href="ts3server://craft412.serveminecraft.net:9987">
                                                                                                </div>

                   <div id="teamspeak_box_2"></div>

                   <div id="teamspeak_text">
                                   <p>TEAMSPEAK<P/>
                               </div>


                   <div id="teamspeak_image"> 
                                           <img src="images/CRAFT412 - Box - Teamspeak.png" alt="TEAMSPEAK">
                                      </div>

Moreover, here is the corresponding CSS styling:

#teamspeak_box a:hover {background: #C62828;
                        transition: all 0.5s ease;}

#teamspeak_text {color: white;
                 bottom: 93px;
                 right: 66px;
                 position: absolute;}          

#teamspeak_image {bottom: 80px;
                  right: 104px;
                  position: absolute;}

#teamspeak_box {width: 159px;
                height: 43px;
                background: #212121;
                bottom: 82px;
                right: 76px;
                position: absolute;
                border-radius: 0px 0px 5px 5px;}

#teamspeak_box_2 {width: 43px;
                  height: 43px;
                  background:#313131;
                  bottom: 82px;
                  right: 191px;
                  position: absolute;
                  border-radius: 0px 0px 0px 5px;}

Answer №1

Make the necessary changes to your HTML and CSS as shown below:

#chat_box {
    display: block;
    width: 200px;
    height: 50px;
    background: #333333;
    position: absolute;
    top: 0;
    right: 50px;
    border-radius: 0 0 5px 5px;
    transition: all 0.5s ease;
}
#chat_box:hover {
    background: #009688;
}
#chat_box a {
    display: block;
    height: 50px;
}
#chat_box_2 {
    display: block;
    width: 50px;
    height: 50px;
    background:#444444;
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 0 0 0 5px;
}
#chat_image {
    display: block;
    position: absolute;
    top: 5px;
    left: 5px;
}
#chat_text {
    display: block;
    color: white;
    position: absolute;
    top: 14px;
    right: 10px;
    font-size: 16px;
    font-family:arial;
}
<div id="chat_box">
    <a href="https://example.com/chatroom">
        <span id="chat_box_2"></span>
        <span id="chat_text">CHAT ROOM</span>
        <img  id="chat_image" src="//dummyimage.com/33x33" alt="Chat Room"/>
    </a>
</div>

Fiddle Link

Answer №2

This is some HTML code...

<section class="section-one">
  
</section>

Here's a snippet of CSS...

section.section-one{
  background-color:blue;
}

section.section-one:hover{
  background-color:green;
}

Hopefully, this code sample proves useful.

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

Incorporate an external website's header and footer onto my own website

In the process of developing a new website, subdomain.example.com, it is important to note that it will operate in a separate environment from example.com. Despite this difference, both sites will feature the same layout in order to maintain a consistent u ...

Tips for Aligning Navigation Tabs/Links at Center in Bootstrap 4

I've been trying to center some tabs on a navigation bar in Bootstrap 4 without success. Additionally, I can't seem to shorten the line underneath the tabs either. Any advice or hints would be greatly appreciated. Thank you in advance. Here is m ...

Challenges arising from updating the size and position of a div element during a mouse move event

As I work on creating a basic horizontal split pane using HTML, CSS, and JavaScript, I have drawn inspiration from this post. While the vertical split pane functions smoothly, the horizontal version seems to be glitchy. The sizes and positions of the div ...

The selection feature is not supported for the type of input element in jQuery

I'm currently attempting to utilize AJAX to send a form with jQuery. However, upon clicking the submit button (which is technically a link), I encountered an error. The error displayed in the console is as follows: Failed to read the 'selection ...

How come my primary content is always spilling onto the header section?

Whenever I try to insert my header (after adding my context), it ends up getting placed below the context, making it invisible. I have attempted adjusting the padding and other sizes, but nothing seems to resolve the issue. https://jsfiddle.net/L30trdfn/ ...

`The opacity of parent elements does not apply to their child elements`

I have been searching extensively and cannot seem to pinpoint the problem. I am trying to adjust the opacity of the parent element, but for some reason, the child elements are not reflecting this change. My attempts at finding guidance through online sear ...

Styling your printed documents in Next.js 10

Within my Next 10 application, I am able to bring in global styles by importing them in _app.js in the following manner: import 'assets/css/app.css' I want to incorporate a print stylesheet as well. Instead of using a @media print { } query with ...

Is there a way to completely remove an element from the dom once the ajax call has returned

I've been struggling to completely remove LI elements and their content, including the checkbox input, from the DOM without success. After an ajax callback, I am calling the following function, but it only removes the contents and not the element its ...

When activating a bootstrap class button, I must ensure the reply-box remains hidden

let replyButton = document.getElementById('reply-button'); let cardBody = document.getElementById('card-body'); let responseBox = document.getElementById('reply-box'); let cancelButton = document.getElementById('btn btn-d ...

Steps to create an HTML list that can be scrolled:

I have designed an HTML list that looks great. However, the issue arises when the list becomes too long - it exceeds the height of the page and there is no scrollbar to navigate through the rest of the list. To address this problem, I need to make the list ...

JQuery is blocking the submission of an HTML form

During my exploration of an AJAX/JQuery tutorial for a registration script that interacts with PHP/MySQL and is submitted via JQuery, I encountered a recurring issue. The problem lies in the form submitting directly to the action page instead of its intend ...

Implementing JavaScript functionality with CSS and HTML on a menu

I'm experiencing issues with my website's menu functionality. Currently, the submenu dropdown works fine, but the main menu is not functional. How can I enable it on the main menu as well? document.addEventListener('click', function( ...

What is the best method to prevent next.js components from overlapping one another?

I recently created a website using next.js and noticed an issue in my index.js file. There is a div that houses the main components of the site: class Page extends Component { render() { return ( <div className={styles.container}> ...

Adjusting jQuery inputmask mask according to dropdown selection: A complete guide

I am utilizing jQuery inputmask to achieve a specific effect: Currently, I have set up a simple formatting for US & Canada phone numbers like this: $("#user_phone").inputmask("mask", { "mask": "(999) 999-9999" }); However, I want to dynamically chan ...

Disabling font-awesome checkboxes

As someone who is new to front-end technologies, I am trying to achieve the following. Despite my efforts to find a solution, I have not been successful so far. Here is the issue I am facing-- I have two master checkboxes labeled 1) I do not like numbers ...

Styling a header using CSS

I successfully coded a header and navigation bar, but I am struggling with setting up elements like "Contact me" properly. My goal is to separate them, add icons, and align the text to the right. I am using Bootstrap 4, but nothing seems to be working, n ...

Is it better to use two div elements with the same v-if condition or wrap them in

When faced with this scenario, what would you consider to be the optimal approach: <div> <div v-if="condition-1">Show something</div> <div v-if="condition-2">Show something else</div> <div v-if= ...

Having difficulty swapping out images on an HTML website template for Internet Explorer

Recently, I obtained an HTML website template that I am currently working on customizing. One of the tasks I have been tackling is replacing some of the existing images with my own. After resizing the new images to match the dimensions of the originals, ...

Easiest and quickest method to retrieve metadata from a website

Currently, I am using preg_match to extract the 'title' from websites, however, it is loading very slowly. Here is what I have so far: This code sends links to a function: <?php foreach($savedLinks as $s) { echo "<div class='sa ...

Discovering Unnecessary CSS & JS Code

Currently, I am tackling a freelance project focused on upgrading a website. The client is requesting specific features from their old site be replicated on the new one. However, the challenge lies in the fact that the old site's CSS and JS are consol ...