Simulate title and ALT prompts with CSS

Source: Internet
Author: User
Many pages have been written during this time. Code Besides repeating some knowledge, I also learned some new things of CSS, maybe old things, But I still hope they will be useful to everyone.

In fact, there are many style applications for a in CSS, because the tag is the only tag that can trigger the action by default, therefore, in many cases, CSS can be used to control the effect that a can achieve Js. For example, the CSS to be introduced today is similar to the title and ALT prompts:

First, let's take a look at the characteristics of this effect. It is nothing more than a prompt layer containing the introduction text when you hover your mouse over it. If you use traditional JavaScript to implement this, we need to set the onmouseover and onmouseout attributes of the object. If we regard the object as link and hover in the attribute, this problem will be clearer, because you only need to set the link attribute of the object to the hidden prompt layer and the hover attribute to the display prompt layer, where is the position of the prompt layer? Of course, it is in the middle of the tag. Currently, the common method is to place the prompt content in the middle of the span tag and include it in the tag, and then set a: link and: different span styles under hover.

The following code is used to explain the simple principle:

[Copy to clipboard]

Code:

<Style>
. Info {position: relative; Background: # FFF; color: #666; text-Decoration: none; font-size: 12px; width: 150px; text-align: center; Border: 1px solid # CCC; Height: 25px; line-Height: 25px;}/* set the link property. Be sure to set it to relative so that the prompt layer can follow the link */
. Info: hover {Background: # Eee; color: #333 ;}
. Info span {display: None}/* set the span to a hidden state */
. Info: hover SPAN/* set the span attribute of hover to the rendering state, and set the position of the prompt Layer */{display: block; position: absolute; top: 30px; left: 60px; width: 130px; Border: 1px solid # ff0000; Background: # FFF; color: #000; padding: 5px; text-align: Left ;}
</Style>
<Body>
<A class = "info" href = "http://www.achome.cn"> www.achome.cn <span> This is my personal blog, which contains some website design and production stuff </span> </a>
<A class = "info" href = "http://www.achome.cn"> www.achome.cn <span> This is my personal blog, which contains some website design and production stuff, I hope you can communicate with each other. </span> </a>
<A class = "info" href = "http://www.achome.cn"> www.achome.cn <span> This is my personal blog, which contains some website design and production stuff, I hope you can communicate with each other. </span> </a>
<A class = "info" href = "http://www.achome.cn"> www.achome.cn <span> This is my personal blog, which contains some website design and production stuff, I hope you can communicate with each other. </span> </a>
<A class = "info" href = "http://www.achome.cn"> www.achome.cn <span> This is my personal blog, which contains some website design and production stuff, I hope you can communicate with each other. </span> </a>
</Body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.