CSS doesn't have the ability to flip a unicode font icon or modify its color when hovered over

I am currently facing 2 issues:

  1. The unicode icon for Twitter is not flipping
  2. None of the unicode icons change color on hover (Only the background)

Check out the jsFiddle link here:

HTML

<span class="icon-twitter-circle"></span> Follow us</br>
<span class="icon-facebook-circle"></span> Like us

CSS

[class^=icon] {
    font-family: Arial, Helvetica, Tahoma, Verdana, "Courier New", "Times New Roman", sans-serif;
    /* UNICODE only! No custom font files. No images */
}
[class^=icon-facebook]:before {
    content: "\024D5";
    content: "\00066";
    color: #0000FF;

    font-size: 1.5em;
    font-weight: bold;
}
[class^=icon-twitter]:before {
    content: "\01F426";
    color: #3366FF;
    font-size: 1em;

    transform: scale(-1, 1); /* Flips the text */
}
[class$=-circle] {
    display: inline-block;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    padding: 0.30em; /* Size of circle */
    margin: 0.10em 0.0em; /* Line spacing */
    border: 1px solid #000;

    line-height: 20px; /* Centers the character Horizontally, on its Y-axis */
    text-align: center; /* Centers the character vertically, on its X-axis */
}
[class^=icon-twitter]:hover {
    color: #fff;
    background-color: #3366FF;
}
[class^=icon-facebook]:hover {
    color: #fff;
    background-color: #0000FF;
}

Note

I recently discovered that transform won't work unless the element is displayed as either display: block or display: inline-block. Therefore, the icon-twitter won't flip until I add

.icon-twitter {display: inline-block; ... transform...

Answer №1

It seems that your hover color is not working because you have set the color on the :before pseudo-element, while attempting to change the color on hover of the actual element. Remember, these are two separate elements.

Try targeting :hover:before instead.

View the fixed version here.

The updated code is:

[class^=icon-twitter]:hover,
[class^=icon-twitter]:hover:before {
    color: #fff;
    background-color: #3366FF;
}
[class^=icon-facebook]:hover,
[class^=icon-facebook]:hover:before {
    color: #fff;
    background-color: #0000FF;
}

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

I'm unable to scroll back up after making an ajax request, as the code automatically scrolls to the bottom of the div

I'm currently working on implementing a JavaScript code to automatically scroll to the bottom of a div after an AJAX request is made. However, I've encountered an issue where I am unable to scroll back up because my JavaScript is constantly check ...

What is the best way to design a button that can toggle a sidebar on and off

I'm struggling with creating a toggle button for the sidebar. I have the sidebar and the button ready, but I'm not sure how to make the toggle function work. Can someone please guide me on what steps I need to take to achieve this? Your help woul ...

exploring the contrast of css versus javascript selectors

Could you please explain the contrast between div#name and #name? Is there a significant difference when using class or id to position an element? Thank you for your help. ...

Text alignment in the horizontal direction does not function as expected within the `<span>` element in Bootstrap 4

The code snippet below is what I am currently working with: <div class="card" > <div class="card-block"> <h4 class="card-title"> <span class="text-left"> ...

Designing checkboxes with accompanying labels

I am looking to create a vertical list of checkboxes with labels, following the layout below: My options [x] Checkbox 1 [ ] Checkbox 2 [ ] Checkbox 3 [ ] Checkbox 4 I have implemented the method suggested in this Stac ...

When using angular.less, the @import feature is functioning correctly but a 404 error is displayed in the

Currently, I am working on a project using AngularJS along with angular.less. To centralize all my constants, I have stored them in one .less file and imported it at the beginning of all my other less files using a relative path: @import "constants" Even ...

What's the best way to determine the background image on this website? I'm in the process of replicating a site on

I have been asked to clone the website in order to create a Wordpress site. The original site is currently on Kajabi platform. I managed to download all images from the Kajabi site by right-clicking and selecting download. However, there are certain image ...

Custom Tooltips arrow is not receiving the CSS styling

I have implemented ReactTooltip from the ReactTooltip library You can view an example here Component Setup <ReactTooltip className={styles.customTheme} id={id} place={placement} effect="solid"> {children} </ReactTooltip> Stylin ...

What is the best way to customize the appearance of the input checkbox in Twitter Bootstrap?

I need help in creating a simple input checkbox since I couldn't find any optional class in Bootstrap. I also checked libraries on GitHub but nothing seems as straightforward as Foundation. Thank you for your assistance. ...

Another choice for object-fit:contain workaround for IE

Is there an alternative option to object-fit: contain that is compatible with Internet Explorer? Below is a snippet of my code: .cbs-Item img { height: 132px ! important; width: 132px ! important; object-fit: contain; <div class="cbs-Ite ...

Resize image dimensions to fit within css div class container

How can I make my image completely fit the size of my div class without cutting off any parts? I've tried using background-size: cover, but it only scales the image to fill the div and cuts off part of it. I also attempted to use object-fit: fill, but ...

What is causing the nested flex container's height to not increase along with its children?

When looking at this codepen, it's clear that the children are overflowing the parent's height. However, the real question is why doesn't the flex parent adjust its height to accommodate the children? One way to fix this issue is by using d ...

Adjusting the size of absolutely positioned div elements

Currently, I am immersed in a project that involves a full-size slideshow background with content positioned above it. The header and footer are required to have fixed margins at the top and bottom, respectively. The central part needs to be resizable wit ...

What are some alternative ways to arrange this main navigation bar?

Check out the website, below the map you'll find an unordered list: HTML code: <ul class="play_navigation"> <li class="active"><a href="#" class="barino_story_bottom">The Story</a></li> <li><a href="#" ...

The background color of the body is being utilized by Div in Internet Explorer version 7

Within my HTML document, I have created a container div that holds several nested divs for a slideshow effect. This "container" div is positioned over the background image of the body element. The CSS styling for the body element is as follows: body { ba ...

Get a polished look using HTML and CSS exclusively

Allow me to illustrate what I am intending to accomplish with an example. div{ width:100px;height:100px; border:3px solid #900; border-radius:0px 0px 140px 0px; } <div></div> I am seeking a method to ...

I'm having trouble with fixing the TypeError that says "Cannot read properties of undefined (reading 'style')." How should I address this issue

I'm having trouble with a slideshow carousel on my website. When the site loads, only the first image is shown and you have to either click the corresponding circle or cycle through all the images using the arrows for the image to display. I'm al ...

Manipulating the visibility of components by toggling on click events according to the existing state in ReactJS

Disclosure: I am still getting familiar with ReactJS I'm currently working on incorporating a dialog window for selecting a country/language on the initial page of my application. Here's the concept: There's a small flag button in the to ...

Unable to display complete content of Ionic 3 webpage

Trying to print a specific part of an Ionic page which contains a long list of items. However, encountering an issue where the entire list doesn't fit on one page and requires scrolling down to view all items. Expecting the print dialog, triggered by ...

Tips for creating spacing between an image and a button when utilizing the routerLink feature in CSS

To enhance the user interface, I've utilized a routerLink with an image to navigate back to the home page, and a button to direct users to add a new customer. Now, I am aiming to create some space between these elements. Previously, I used "& ...