Displayed information on hover

https://i.sstatic.net/XVQWG.jpg

I've been searching high and low for a simple textbox that appears when you hover over an image, positioned either to the left or the right. I don't need anything too fancy - just a rectangular box with a background color that stands out against the other images on the page.

I did try using the 'Title' tag in HTML, but it didn't quite meet my needs as it was too slow. I'm looking for something more responsive and customizable. The text box should only appear upon hovering over the image, and disappear once the mouse moves away. It would also be a nice touch to have a cursor appear when hovering over the image.

Answer №1

To create a hover effect displaying the title attribute, you can utilize a pseudo element.

.element {
    position: relative;
}
    
.element:hover:after {
    position: absolute;
    content: attr(title);
    display: inline-block;
    left: 0px;
    top: 0px;
    padding: 5px;
    background-color: black;
    color: white;
}
<div class="element" title="Hover Over Me">
    <p>Move your cursor over this text</p> 
</div>

Answer №2

In the world of HTML, there is a special event called "onmouseenter" that can be used to trigger certain actions.

<div onhover="box()"></div>

This event allows you to execute JavaScript code, which in turn can show or hide elements like a div or a span with a positioned relative to its original location. However, achieving this effect may require some CSS expertise.

Answer №3

Utilizing the mouseover event, a solution is presented to display a text input and hide it once the user modifies its value. The CSS implementation includes some clever hacks for visual appeal, with crucial elements such as:

  • #container featuring position: relative; (allowing absolute positioning of children inside)
  • #myImg styling with float: left; (with a defined width that isn't excessively wide)
  • #textContainer with
    position: absolute; display: none;
    (its left property aligned to #myImg's width)
  • #more-content-to-right employing float: left (and specifying a reasonable width)
  • #more-content-below utilizes clear: both

In live deployment, borders would likely be omitted and more robust techniques employed for aesthetic enhancements.

function showTextContainer(){
  document.getElementById("textContainer").style.display = "block";
}
function hideTextContainer(){
  document.getElementById("textContainer").style.display = "none";
}
#container { position: relative; width: 530px; margin: 0 0; padding: 2px; }
#myImg { height: 100px; width: 200px; float: left; }
#textContainer { position: absolute; left: 200px; top: 50px; height: 1.3em; width: 200px; display: none; }
#textbox {width: 98%; }
#more-content-to-right { float: left; height: 100px; width: 300px; }
#more-content-below { clear: both; height: 100px; width: 508px; }
.bordered { border: 1px solid gray; margin: 3px;}
<div id="container" class="bordered">container<br/>
  <div id="myImg" class="bordered" onmouseover="showTextContainer()">img</div>
  <div id="textContainer" class="bordered">
    <input id="textbox" placeholder="type stuff here" onchange="hideTextContainer()" />
  </div>
  <div id="more-content-to-right" class="bordered">more content to right</div>
  <div id="more-content-below" class="bordered">more content below</div>
</div>

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

Retrieve and utilize the dynamically produced values from the application's app.js in a script that is accessed using

In my Express.js Node web app, I generate a string in app.js during initialization: // app.js var mongourl = /* generated based on process.env.VCAP_SERVICES constant */; There is a script that I import into app.js using require(): // app.js var db = req ...

Is QA supported by LG WebOS 3.5 through webdriver?

I've been experimenting with Javascript ( nodejs ) and have successfully automated browser operations using selenium-webdriver on a local server. However, I am facing challenges when trying to automate tasks on my LG WebOS 3.5 TV. Does anyone know how ...

What are some ways to prevent an image from spilling out of its designated container

Despite my attempts at researching and seeking advice from someone more experienced in CSS styling, we were unable to find a solution to this issue. You can view the JS Fiddle link here: https://jsfiddle.net/haha78sr/. The image with the id, ctl00_cphB ...

Can images be accessed and displayed on an HTML page by opening a directory and reading file data using Javascript?

Is it feasible in JavaScript to access a directory, read an image file, and display it in HTML? While it may not be possible to directly open files in a directory using JS, I am looking for a way to achieve the following: I have an XML file that includes ...

Error: Trying to access a property that is undefined (specifically referencing 'rendered') has resulted in an uncaught TypeError

As a newcomer to React, I'm attempting to create a headless WordPress application. However, when I fetch a post, I only receive the first value. After fetching the post, I save it in the state: componentDidMount() { this.setState({ lo ...

What is the process for constructing an object to resemble another object?

After collecting input data, I have created an object based on those values. Here is an example of the generated object: var generate_fields = { name: "Mike", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d9dddf ...

Instead of leaving an Enum value as undefined, using a NONE value provides a more explicit

I've noticed this pattern in code a few times and it's got me thinking. When you check for undefined in a typescript enum, it can lead to unexpected behavior like the example below. enum DoSomething { VALUE1, VALUE2, VALUE3, } f ...

Manipulating child classes using jQuery

I am struggling to display an X icon next to a tab on my page when the tab is clicked, but I am facing difficulties in toggling its visibility. The issue arises when trying to access the span element within the tabs. $('.tabs .tab-links a').on(& ...

Guide on using CSS to position text around an image

I need to figure out a way to wrap text around an image positioned in the bottom left corner of a CSS table. Since the amount of text may vary each time I use it, I am wondering if there is a solution for this and how I can achieve it? ...

What can be done to maintain column placement when using grid-row span?

In my CSS Grid layout, I have a 3 x 3 grid setup. Within a row, I have three items labeled A, B, and C. I am trying to make item C span two rows using grid-row: 1 / span 2, but it's not appearing in the correct column. It's showing up in the fi ...

Comparison between HighChart, D3.Chart, and C3.Chart

In need of charting capabilities for my CMS Application. I am interested in incorporating Pie Charts, Area Charts, Column Charts, Bar Charts, and Gauge Charts. After doing some research online, C3.js and HighCharts.js stood out to me as promising options. ...

Challenges with Selenium Web Scraping

I'm currently in the process of creating a web scraper that extracts data from the Beatport top 100 chart. However, I've encountered an issue where some items are successfully located while others result in errors. def scrape_beatport(): user ...

Kartik's gridview in yii2 has a unique feature where the floating header in the thead and tbody are

I'm looking to create a table gridview with a floating header, where the tbody and thead are not the same. The image appears after refreshing the page, before the modal is refreshed. After refreshing the modal, this modal is inside pjax and it sets t ...

Exploring how to browse and dynamically assign image sources with JavaScript/jQuery in an Asp.net mvc 4 framework

On my .cshtml page, I have an <img/> tag. <img id="ImageID" alt="" width="100%" height="100%" /> I want to dynamically set the src attribute by selecting the image file path using a file control. Although I attempted the following code in my ...

Default file is still generated by Sass even when variables are modified

Currently, I am in the process of modifying some variables for my customized version of Bootstrap. At the moment, I have the Bootstrap SCSS files along with my own variables file. This is how my file appears: @import "/path/to/bootstrap"; $blue: #42a5f ...

What's the best way to enable touch scrolling for items within a div container?

I am in the process of creating a code snippet that will allow users to scroll through items within a div, similar to a spinning wheel or slot machine. While I am aware of an existing solution for iPhone and iPod, I want to develop a simpler, more streamli ...

Tips on pausing a moving image from left to right and restarting it later

Is there a way to pause the left to right moving image at the end and then restart the loop? I tried utilizing this website link for assistance: https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_animation-delay Unfortunately, I couldn't fi ...

Animate linear-gradient using jQuery script

I have been searching for a circular progress bar plugin but haven't found one that suits my needs, so I decided to build my own using pure CSS: http://jsfiddle.net/9RFkw/ While it looks great, there are two issues I am facing: 1.) When at 25% in F ...

The AngularJS controller does not have its array initialized

Creating a small dialog controller where questions, answers, and correct answer index can be added. The goal is to allow users to add multiple questions and save them in an array. Everything works smoothly until attempting to push the JSON data of the que ...

Ways to create a unique animation for reducing the width of a div in a specific direction?

Currently, I have managed to animate the decrease in width of a div element. However, it is currently decreasing from right to left, and I would like it to decrease from left to right instead. Can someone please provide guidance on how to achieve this? ...