Try this:
HTML
<p class="head_ico_p" title="profile">
<img class="head_ico" src="https://app.getfloop.com/img/dashboard/app/placeholder-app-icon.png"/>
</p>
<p class="caption">Edit Profile</p>
CSS
.head_ico_p{
width:100px;
margin:20px auto 0;
text-align:center;
}
img{
width:70px;
}
.caption{
display:block;
width:100px;
margin:0 auto;
background:#333;
color:#fff;
text-align:center;
padding:10px
}
You can achieve the desired effect as shown below:
.head_ico_p[title]:hover:after { content:attr(title); background-color:#000000; border:solid 1px #ffffff; padding:5px; color:#ffffff; display:block; width:330px; height:30px; } body { background-color:#dddddd; }
<p class="head_ico_p" title="profile"><img class="head_ico" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150"/></p>
:after
psudeo-class is used in CSS to add another "element" after the element that is being selected. This element can be effected by all standard styles and selectors, such as :hover
. Note that a :before
psudeo-class also exists, for adding another "element" before the element being selected. content
attribute can set the content of an element created by :before
or after
to a predefined value. This can be specified in the CSS ( content:"xyz";
) or by an attribute. The latter is what you are looking for, and uses the CSS attr
function to pull the contents of an attribute into the CSS code as the value for content
. The code shown in the JSFiddle above uses a combination of the above (and some other basic CSS) to create the desired tooltip effect.
title
). If you don't want it to disappear when you're not hovering, all that you need to do is remove the :hover
psudeo-class from the CSS selector making the tooltip. title
, as title
can render a default tooltip on hover (the browser does this). Code with data attributes would simply use data-xyz
instead of all occurrences of title
. Note that xyz
can be replaced by whatever you want. <html> <head> <style type="text/css"> .test{ display:inline-block; box-sizing:border-box; width:80px; height:110px; background:url('http://s15.postimg.org/fjgl2u3h3/Cvt_Lr.png') no-repeat #000; color:#fff; background-color:#000; text-align:center; padding-top:85px; } </style> </head> <body> <a class="test" href="#">Profile</a> </body> </html> somethin like that. But you will need to cut the white space from the image. Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.