The task we are going to perform in this article is how to display fonts when hovering the mouse over an image. Let’s dive into this article and take a quick look at hover and mouseover in HTML.
The onmouseover event in HTML is triggered when the mouse pointer touches an element. When the mouse pointer leaves an element, an event called onmouseout occurs.
The :hover CSS pseudo-class matches when the user interacts with an element using a pointing device, but it is not always activated. Normally it is activated when the user hovers the cursor over the element (mouse pointer).
grammar
The following is the syntax of hover -
:hover
To better understand displaying fonts when hovering over an image, let's look at the following example.
Example
In the example below, we make the font visible when the mouse is hovered over the image.
<!DOCTYPE html> <html> <body> <style> .img { position: relative; width: 200px; height: 200px; float: left; margin-right: 10px; } .img div{ position: absolute; bottom: 0; right: 0; background: black; color: white; margin-bottom: 5px; visibility: hidden; } .img:hover{ cursor: pointer; } .img:hover div{ width: 150px; padding: 8px 15px; visibility: visible; opacity: 0.7; } </style> <div class="img"> <img src="/static/imghwm/default1.png" data-src="https://www.tutorialspoint.com/static/images/logo-color.png?x-oss-process=image/resize,p_40" class="lazy" style="max-width:90%" style="max-width:90%" alt="How to display font on mouseover of image?" > <div>TP HTML LOGO</div> </div> <div class="img"> <img src="/static/imghwm/default1.png" data-src="https://www.tutorialspoint.com/static/images/logo-color.png?x-oss-process=image/resize,p_40" class="lazy" style="max-width:90%" style="max-width:90%" alt="How to display font on mouseover of image?" > <div>TP JAVA LOGO</div> </div> </body> </html>
When the script executes, it will generate an output that displays the image on the web page. If the user hovers over the image, it will display a text description of that specific image on the page.
Example
In the example below, we make the font appear when the mouse is hovered over the image, and cover the entire image.
<!DOCTYPE html> <html> <body> <style> .tutorial { position: relative; max-width: 500px; } .tutorial img { width: 100%; } .fulltext { box-sizing: border-box; width: 100%; height: 100%; position: absolute; top: 0; left: 0; text-align: center; padding-top: 30%; background-color: #EAFAF1 ; color: black; } .fulltext { visibility: none; opacity: 0; transition: opacity 0.3s; } .tutorial:hover .fulltext { visibility: visible; opacity: 1; } </style> <div class="tutorial"> <img src="/static/imghwm/default1.png" data-src="https://www.tutorialspoint.com/static/images/logo-color.png?x-oss-process=image/resize,p_40" class="lazy" src=https://www.tutorialspoint.com/java/images/java-mini-logo.jpg alt="How to display font on mouseover of image?" > <div class="fulltext"> LEARN JAVA...!<br> </div> </div> </body> </html>
When you run the above script, an output window will pop up to display the image on the web page. If the user moves the mouse over the image, it will display text covering the entire image.
Example
Execute the following code and observe how the font appears when you hover the mouse over the image.
<!DOCTYPE html> <html> <body> <style> div { position: relative; top: 0px; left: 0px; width: 400px; height: 400px; border-radius: 50%; overflow: hidden; text-align: center } img { width: 400px; height: 400px; position: absolute; border-radius: 50% } img:hover { opacity: 0; transition:opacity 2s; } heading { line-height: 40px; font-weight: bold; text-align: center; position: absolute; display: block } div p { width: 420px; line-height: 20px; display: inline-block; padding: 200px 0px; vertical-align: middle; height: 450px } </style> <div> <img src="/static/imghwm/default1.png" data-src="https://www.tutorialspoint.com/static/images/logo-color.png?x-oss-process=image/resize,p_40" class="lazy" alt="How to display font on mouseover of image?" > <p>Welcome to Tutorialspoint</p> </div> </body> </html>
When the script is executed, the output window will pop up, making the image appear as a circle on the web page. When the user hovers over the image, it will display the text.
The above is the detailed content of How to display font on mouseover of image?. For more information, please follow other related articles on the PHP Chinese website!

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools