How can you display an image with text on hover in a simple way?

Is there a way to display an image (a company logo sized at 150 x 100 px) when a user hovers over the company name? The image should appear on the right side of the name.

I am uncertain whether this can be achieved with CSS3 alone or if I would need to use jQuery, which is not my preferred option.

Do you have any suggestions or ideas for how to accomplish this?

This is my HTML structure:

<div class="supplier_box_top">
    <p class="name">Company Name</p>
    <p class="city">Country</p>
    <p class="info" ><a href="#" target="_blank" id="1" class="show_info_box">nfoBox</a></p>
    <p class="site_link"><a href="javascript:void(0)">www.your-company.com</a></p>
</div>

Answer №1

Using CSS3 makes it simple to achieve this effect:

.name:hover::before {
    content: url(your_custom_image.jpg);
    float: right;
}

Please remember that the image path is relative to the CSS file location.

This basic solution results in the image floating next to the company name on the right side. If you desire a more intricate design, let me know.

However, if compatibility with IE7 and earlier versions is necessary, you can include the image in the markup as shown below and apply similar styling for hover:

HTML:

<div class="supplier_box_top">
    <p class="name">
        <img class="company_image" src="my_company_image.jpg">
        Company Name
    </p>
    <p class="city">Country</p>
    <p class="info" ><a href="#" target="_blank" id="1" class="show_info_box">nfoBox</a></p>
    <p class="site_link"><a href="javascript:void(0)">www.your-company.com</a></p>
</div>

CSS:

.name .company_name {
    display: none;
}
.name:hover .company_name {
    display: block;
    float: right;
}

Answer №2

If you want the <img> to appear after the Company Name .name, consider using adjacent a + b or general a ~ b sibling selectors to show the image:

img.logo {
   display: none;
}

.name:hover ~ img.logo {
    display: inline;
}

Alternatively, you can place the image within the same paragraph and implement the following method:

<p class="name">Company Name <img src="" /></p>
.name {
   position: relative;
}

.name img {
   position: absolute;
   left: 100%;
   display: none;
}

.name:hover img {
    display: inline;
}

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

Trigger the next button click event using jQuery

Is it possible to implement a slideshow on my website where clicking a button displays the relevant slide? My goal is to incorporate a timer that will automatically click the next button after 3 seconds, enabling the slideshow to transition automatically. ...

Updating Tailwind CSS to accommodate older web browsers by converting modern rgba() notation to be browser-compatible

I am facing a challenge with Tailwind CSS v3+ as it builds colors into the rgb space/color notation that is not compatible with an older browser (Safari 11) that my web app now needs to support. For example, rgb(163 160 158 / var(--tw-bg-opacity) The iss ...

Utilize the hexadecimal color code as a string within the darken function

When working with a less style, I have a string variable. @colorString: 'DADADA'; I can convert it into a color: @color: ~'#@{colorString}'; Then, I am able to use @color to define a value in a style: div { color: @color } However ...

The <Button> element is incompatible with popups. (HTML, CSS, JS)

I've been struggling with this issue. I used CSS color values to create a smiley face, but when I added a button it messed up the design (adding an unwanted circle around the center of the smiley). I attempted to synchronize the button tag with the po ...

Rearranging Twitter Bootstrap Grid Columns

Is it possible to rearrange columns in Bootstrap without using col-sm-pull-12/col-sm-push-12? I'm struggling to achieve the desired layout. Are there any alternative methods to accomplish this task? Check out this JSFiddle for reference. <div cla ...

Significant delay in processing second jQuery Ajax call

Attempting a simple Ajax call with page content refresh using the following code snippet: $("a.ajaxify-watched").bind("click", function(event) { $item = $(this); $.ajax({ url: $(this).attr("href"), global: false, type: "G ...

Keep a stack to hold the content within the div element

I've been dealing with a datatable and successfully managed to open a details page within the same div when a row is clicked using divname.load(@url.action(''). However, I am now looking to add a close button on the details page so that I c ...

Creating a Full Height Background Image with a Responsive Width Using Jquery

I am facing an issue with my background image dimensions of 1400 in height and 1000 in width. When using any full-screen background jQuery plugin or code, the image crops from either the top or bottom to fit the entire screen. However, I am looking for a s ...

The Limits of JavaScript Tables

Currently facing an issue with a webpage under development. To provide some context, here is the basic layout of the problematic section: The page features a form where users can select from four checkboxes and a dropdown menu. Once at least one checkbox ...

steps to overlay an image over another in bootstrap:

I am trying to place an image over another image. Here is the code I have used: <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8> <meta name="viewp ...

Inexperienced with Bootstrap/CSS: Cannot open dropdown by clicking (CDN properly installed)

I am having trouble getting my Bootstrap dropdown to toggle correctly, despite placing the JS script last. I have checked multiple resources and it was suggested that CDN may not have been imported correctly. I have also tested this on different browsers w ...

Modifying<strong>superscript</strong> design

Is there a way to change the style of <sup> elements using CSS without removing them from the HTML code? I want to make them look like regular text. Basically, I want the result of <div>Some <sup>random</sup> text.<div> to ...

How to Make Your Site/Content Fade In with jQuery Upon Loading?

Is there a way to add a fade-in effect to a website once it has finished loading, in order to avoid any sudden changes and ensure that the content appears smoothly? It might be simpler if the fading effect is applied only to certain sections, such as head ...

Tips on creating a clickable drop-zone using jQuery

When I drop a file onto the drop-zone in my web form application, I can easily upload it by clicking the button below the zone. However, I am looking for a way to make the drop-zone itself clickable, so that when clicked, it opens the upload file dialog wh ...

"Utilizing Twitter Bootstrap to create full-width input fields with pre

Presently utilizing bootstrap-2.1.1 In my row-fluid, I have 2 columns with input-prepends inside. Below is a snippet of code: <div class="row-fluid"> <div class="span6"> <ul> <li> <div class="input ...

Using the Greasemonkey browser extension, one can employ the waitForKeyElements utility to trigger a function once a designated element becomes visible on the webpage

(In connection to the question I posted on Stack Overflow). I have been developing a userscript for metal-archives.com, which can be found here. When you navigate to a band page (like this example), you will see the DISCOGRAPHY section and its sub-tabs ...

I am having trouble modifying the content of a div using Jquery append

I have a plan to use jQuery to change images. I have multiple image files named choose 01.png, choose 02.png, and so on. When an image is clicked, I want it to be replaced with the corresponding choose 01.png file. Once 5 images have been clicked and chang ...

Is it possible to fill dropdown menus on a webpage using jQuery or JavaScript without the need for an ajax call?

Currently, I am looking to populate multiple dropdown lists using jQuery when the page loads rather than relying on ajax responses to events. My Controller is responsible for creating several List objects that will be used for these dropdowns. Right now, I ...

Achieving Right Alignment of SVG Next to an <h4> in Bootstrap 5

I'm encountering an issue where I am attempting to align an SVG icon to the right of an H4 element and center it vertically using Bootstrap 5, but it's not working as intended. <div class="container-fluid"> <div class="r ...

Is it possible to customize the appearance of HTML input fields pre-populated by the browser

My ASP.NET MVC application has a login page: <form id="account" method="post"> <h2>Use email account to log in.</h2> <hr /> <div asp-validation-summary="ModelOnly" class=& ...