When trying to display a pseudo-element image on a parent element's hover state, it

Trying to incorporate multiple images using pseudo-elements when a parent list-item is hovered over. Upon examining in Chrome, the pseudo-element displays but the .png image isn't showing correctly. I'm questioning if the selectors are being used properly or if there is another issue with the code. You can view a live example here.

Here's the HTML:

<main>
  <section id="results">
    <ul>
      <li class="term-list">
        <dl>
          <dt class="term">hello</dt>
          <dd class="pronounce">[ <strong>he</strong>-lo ]</dd>
        </dl>
      </li>
      <li class="term-list">
        <dl>
          <dt class="term">word</dt>
          <dd class="pronounce">[ <strong>wurd</strong> ]</dd>
        </dl>
      </li>
      <li class="term-list">
        <dl>
          <dt class="term">another</dt>
          <dd class="pronounce">[ uh-<strong>nuth</strong>-er ]</dd>
        </dl>
      </li>
      <li class="term-list">
        <dl>
          <dt class="term">aviation</dt>
          <dd class="pronounce">[ ay-vee-<strong>ay</strong>-shun ]</dd>
        </dl>
      </li>
      <li class="term-list">
        <dl>
          <dt class="term">hello</dt>
          <dd class="pronounce">[ <strong>he</strong>-lo ]</dd>
        </dl>
      </li>
    </ul>
  </section>
</main>

CSS:

.term-list {
  border-top: 1px solid gray;
  color: gray;
  padding: 15px 10px;
}

.term-list:last-child {
  border-bottom: 1px solid gray;
}

.term-list:hover,
.term-list:hover + .term-list {
  border-top: 1px solid white;
  -webkit-transition: border-top .2s ease-in-out;
  -moz-transition: border-top .2s ease-in-out;
  -ms-transition: border-top .2s ease-in-out;
  -o-transition: border-top .2s ease-in-out;
  transition: border-top .2s ease-in-out;
}

.term-list:hover {
  color: white;
  -webkit-transition: color .2s ease-in-out;
  -moz-transition: color .2s ease-in-out;
  -ms-transition: color .2s ease-in-out;
  -o-transition: color .2s ease-in-out;
  transition: color .2s ease-in-out;
  cursor: pointer;
}

.term-list:hover::last-child {
  border-bottom: 1px solid white;
  -webkit-transition: border-bottom .2s ease-in-out;
  -moz-transition: border-bottom .2s ease-in-out;
  -ms-transition: border-bottom .2s ease-in-out;
  -o-transition: border-bottom .2s ease-in-out;
  transition: border-bottom .2s ease-in-out;
}

.term-list:hover dl::after {
  content: "";
  display: inline-block;
  position: absolute;
  right: 5px;
  top: 50%;
  margin-top: -20px;
  width: 40px;
  height: 40px;
  background-size: 40px 40px;
  background: url("https://preview.c9users.io/patbrennan/demo-project/launchschool/249/dictionary/images/arrow-right.png") 0 0 no-repeat;
}

Answer №1

Update your

background: url("https://preview.c9users.io/patbrennan/demo-project/launchschool/249/dictionary/images/arrow-right.png") 0 0 no-repeat;

to

background-image: url("https://preview.c9users.io/patbrennan/demo-project/launchschool/249/dictionary/images/arrow-right.png");

Answer №2

Make Changes

The response provided contains some inaccuracies. It is worth noting that 40px 40px is indeed a valid value. The issue arises from the fact that the shorthand property for background takes precedence over the initially defined background-size. To prevent this, any overrides should be positioned after the shorthand property declaration.

Initial Response

Your image may not actually be sized at 40px by 40px.

https://i.sstatic.net/4Vsuj.png

The image appears to be correctly set up; however, only the top left corner is visible, which happens to be transparent. By applying background-size: contain; on .term-list:hover dl::after, you can restrict it to match the pseudo-element's width and height accurately.

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

Tips for exchanging divs in a mobile view using CSS

Illustrated below are three separate images depicting the status of my divs in desktop view, mobile view, and what I am aiming for in mobile view. 1. Current Status of Divs in Desktop View: HTML <div id="wrapper"> <div id="left-nav">rece ...

What is the best way to include a JavaScript function in a dynamically generated div?

By clicking a button, I am able to dynamically generate a table row that contains a div element with the class "contents." $(document).on("click", ".vote", function() { // Removing selected row var rowLoc = this.parentNode.parentNode. ...

Aligning text to the center and having it displayed on either side of it

Hey there, I need help with the following: <div id='1'></div> <div id='2'></div> <div id='3'></div> I want to place a single word into each div. The width of each div should be ...

The React className attribute has surpassed the maximum line length of 120 characters, causing an error

Here's the element in question: <div className={`my_container ${theme} ${isSpanishLanguage && 'spanishLanguage'} ${isEnglishLanguage && 'englishLanguage'}`}></div> I am encountering an error due to the line being too l ...

Ways to customize the appearance of Bootstrap 4 tooltips

I'm having trouble customizing my Bootstrap 4 tooltip. I want to adjust the background color, height, width, and border, but I can't figure out how to style it to my liking. Here is the HTML code I am using: <i class="fa fa-question-circle" ...

Update the value of a JSF managed bean property for a h:SelectOneMenu using JavaScript

Hello, I have a unique method of injecting HTML code at runtime into my web page using JavaScript. The specific piece of code that I am cloning and inserting is as follows: <div id="any"> <h:selectOneMenu value="#{browserOSList.browserXP[0]}" ...

Issue: Map container not located when implementing a leaflet map with Angular

Here is the complete error message: core.js:6479 ERROR Error: Map container not found. at NewClass._initContainer (leaflet-src.js:4066) at NewClass.initialize (leaflet-src.js:3099) at new NewClass (leaflet-src.js:296) at Object.createMap [a ...

Guide to positioning elements in CSS

I'm struggling to get all the elements to align in a single row. I've tried using display: inline-block, but it's not working as expected. I'm working with DataTables and I want the button images to be aligned with the page number box. ...

The function FormatCurrency is non-existent

I need assistance with converting a textbox value into a currency using the jquery.formatCurrency-1.4.0.js plugin. My JavaScript function is set up like this: $(document).ready(function() { $('.currency').blur(function() { $(&apo ...

Troubleshoot: Issues arising when loading DataTables using AJAX with MYSQL

For some reason, I'm receiving an invalid JSON response from this code. The objective is to showcase SQL data in a table with search and sort functionalities using https://datatables.net/. Can you pinpoint where the issue might lie? GET.PHP $mysqli ...

Direction flex property

Could someone please clarify the significance of maintaining flex direction as column in this scenario? Changing it to row or row reverse causes some parts of the image to shrink in width. Check out the JS Fiddle example: https://jsfiddle.net/fbshqg0c/7/ ...

The function getSelection().focusNode does not function properly within a specified ID

My current code allows for text to be bolded and unbolded using Window.getSelection(). I found the initial solution here: Bold/unbold selected text using Window.getSelection() It works perfectly without any issues. However, when I tried to modify the code ...

send a value through the span input box

I have a form with a submit button. After implementing jQuery, the page will display: for(var i=0 ; i <10 ; i++){ '<span class="ioAddConcept">'+ currentConcept[i] +'</span>\n\ with\n&bsol ...

The behavior of the jQuery slick slider is acting oddly

Currently, I have implemented the Slick Slider for my product loop in order to display the products in a slider format. However, upon the initial page load, there appears to be a significant white gap below the products. Interestingly, when I interact with ...

How can I define the boundaries for the scrolling of a static background image?

Is there a way to limit how far a fixed background image can scroll down a page? Essentially, is it possible to change the background attachment to static when the bottom of the background image is 10px away from the bottom edge of its div container? In t ...

There are spaces on both edges of the banner

I'm facing an issue with my banner width when trying to make it expand across the page. Despite using width: 100%, it still has a gap of around 5px on either side. Any insights on why this might be happening? CSS .banner { width: 100%; height: 300px ...

What are some possible causes for an iframe failing to load?

When it comes to iframes failing to load their content, there could be various reasons causing this issue. I recently encountered a situation where an iframe on my site's "thank you" page was not displaying any content when inspected using Chrome dev ...

Utilizing lz-string to import and export game data in JavaScript for saving purposes

Lately, I've been discovering a multitude of web-based games that allow you to export and import your save game data. When you click "export," you receive a string of random characters as your save file. I want to store my save game state using lz-str ...

The left and right boxes have the same background color, but the left box is filled with lots of content while the right box only has a small

For my layout, I am using two boxes - a left_box with float:left property, and a right_box also with float:left property. The left box contains a lot of content and images, while the right box has only some content and images. Initially, everything was wo ...

Scrolling function for an automatically adjusting menu bar

I need help creating a dynamic menu that automatically adjusts in size as the user scrolls down. I found a script online and added it to my HTML file like this: <script type="text/javascript"> $(function() { var header = $(".large"); $(windo ...