Hover over CSS sprite

My anchor tag looks like this:

<a href="#">
   <i class="ico01"></i>
   <span>Text</span>
</a>

The ico01 class applies an image using CSS sprite. I want to change the background color of the entire content inside the anchor (span + i) when the mouse hovers over it. However, currently, only the text (span) is affected by the hover effect. Am I missing something?

Here's a JS Fiddle link showcasing the issue: https://jsfiddle.net/0esbmusq/1/

Thank you for your help!

Answer №1

p {
  display:inline;
}

p:hover {
background-color:gray;
}

Answer №2

Here is a suggestion to try:

a{
   display:block;
}

.ico01 {
  background: url('https://download.seaicons.com/icons/marcus-roberto/google-play/512/Google-Chrome-icon.png') no-repeat -10px -24px;
  width: 492px;
  height: 488px;
  display:block;
}
a{
  display:block;
}
a:hover {
  background-color:red;
}
<a href="#">
  <span>Google</span>
  <i class="ico01"></i>
</a>

Answer №3

Do you intend to do this?

a:hover span{background-color:black};
<a href="#">
   <i class="ico01"></i>
   <span>Text</span>
</a>

Answer №4

To make the link visible, be sure to set the display property to block.

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

Using the html5-canvas element to drag connected lines

Here is an example of creating four points and connecting them: sample. My goal is to make it possible to drag the entire line connection when clicking on it, but when clicking on a circle, only that specific circle should be extended (already implemented ...

Inconsistency in css asset URLs across various pages discovered while working with Rails

When using assets stylesheet to load a CSS file, I noticed that it only loads on the index page. Upon inspecting with F12, the console shows the URL for other pages as well, which appends "/cloths" to the asset path. I am currently utilizing the default la ...

Is it possible to turn off wrapping behavior within a div using CSS3 or Bootstrap?

Currently, I am working with code that utilizes Bootstrap 2. <div class="row-fluid"> <div class="span4">Some text 1</div> <div class="span4">Some text 2</div> <div class="span4 ...

What steps can I take to ensure that an image does not exceed the size of its parent tag?

Is there a way to ensure that items placed in a container do not exceed the boundaries of the container? I am trying to use my logo as the home button, but when I set the image height and width to 100%, it becomes larger than the nav bar. The CSS for the n ...

Database stores line breaks in a structured format

As I work on creating a posts section for my readers, I have encountered an issue. When a user adds a new post, it gets saved into the database in this format: Some say the world will end in fire,<br /> Some say in ice.<br /> From what I’ve ...

Generating replicated elements at varying positions

After discovering that my previous question, which can be found here, is currently not feasible due to limitations with html2canvas only taking 'snapshots', I have chosen to approach the problem differently. The new approach involves making an o ...

Dynamic input fields with autocomplete functionality

I have attempted to implement the solutions provided elsewhere on this specific issue, but unfortunately they do not seem to be working for me. It is highly probable that I am making some mistake in my approach... My main objective is to achieve what is me ...

Update Symfony form class to replace the HTML5 input type from "text" to "number"

Attempting to implement an input with the "number" type for HTML5 frontend support has been a challenge. Here is my form class: class MyType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { ...

Why does the browser keep converting my single quotation marks to double, causing issues with my JSON in the data attribute?

This task should be straightforward, but I seem to be facing a roadblock. I am trying to insert some JSON data into an input's data attribute, but the quotes in the first key are causing issues by prematurely closing the attribute. Here is the code ...

D3 Treemap for handling extensive sets of data

I am uncertain if there exists a method to incorporate the desired feature. I am seeking a solution similar to zoomable treemaps, but to initially load a limited number of child levels and then dynamically add more child nodes without requiring a node clic ...

Using jQuery within MediaWiki pages beyond just Monobook.js or extensions is a powerful tool

Currently, I am experimenting with some jQuery functionalities in a MediaWiki content page to enhance various features. I have referred to the following resources: http://www.mediawiki.org/wiki/Manual:$wgRawHtml (particularly for incorporating Paypal but ...

Applying CSS to both pop-up and desktop interfaces can be achieved through the use of media queries or alternative solutions

I am facing a dilemma where I need to display the same content on both a pop-up and desktop view. While I have already implemented media queries to adjust the content for desktop and mobile views, I am struggling with displaying the same content on a pop ...

Identify which anchor tag from the group with the matching class was selected and retrieve its unique identifier

There are multiple anchor tags with the same class in my code. <a href='' id='id1' class='abc'>Link 1</a> <a href='' id='id2' class='abc'>Link 2</a> <a href='&apos ...

The label is not displaying the specified font-family in CSS

Below is a snippet of code that I am having trouble with: testing some content Additionally, here is the CSS code for it: label { font-family: "Andale Mono"; } The issue I am facing is that no matter which font style I try to apply, it does not seem to ...

Centered HTML Columns on the Screen

Figuring out this simple html + css issue is proving to be quite challenging for me. I am attempting to create a '3 column' layout. I envision a central column (approximately 10em in width) with two additional columns flanking it on each side (e ...

Retrieve CSS hover values using jQuery

When the page is loaded, I need to execute a function that retrieves the CSS background image settings as well as the hover background image setting, which I intend to use in a different way. The only technique I have come across requires an actual mouseo ...

Making changes to an AngularJS property updates the value of an HTML attribute

One of my pages, base.html, contains the following code: <html lang="en" data-ng-app="MyApp" data-ng-controller="MyController"> <body style="background-color: [[ BackgroundPrimaryColor ]]"> . . . {{ block ...

Using JavaScript to alter CSS styles with dashes

Currently, I'm delving into the world of manipulating CSS using JavaScript: img.style.borderRadius = "100%"; img.style.border = "9px solid #ffffff"; img.style.boxShadow = "0 0 5px #00000070"; img.style.margin = "20px"; I'm wondering how to chan ...

How to toggle between checked and unchecked states using jQuery within AngularJS?

After reloading, the checkbox should maintain its checked or unchecked state. This functionality can be achieved using a directive controller. var checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {}, $checkboxes = $("#c ...

Issues with hover menu arise following relocation of primary menu

#header { height: 108px; width: 1140px; background-color: #faa220; position: relative; } #Logo2 { height: 108px; float: left; } #header links { height: 50px; float: left; list-style: none; padding-top: 10px; } #container { overflo ...