最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Displaying some text when mouse is over an input text box - Stack Overflow

programmeradmin5浏览0评论

I have an input text box, on which I would like to display some text area when the user's mouse get over it, giving to him informations on the text to enter. here is my HTML code :

<html>
<body>
<style type="text/css">
.mouseover 
{



}

</style>
<span onmouseover="this.classname='mouseover'" onmouseout="this.classename=''"></span>
<input id="mybox" type="text" />

</body>
</html>

What is the best CSS trick that would help to do that ? Thank you for help in advance.

I have an input text box, on which I would like to display some text area when the user's mouse get over it, giving to him informations on the text to enter. here is my HTML code :

<html>
<body>
<style type="text/css">
.mouseover 
{



}

</style>
<span onmouseover="this.classname='mouseover'" onmouseout="this.classename=''"></span>
<input id="mybox" type="text" />

</body>
</html>

What is the best CSS trick that would help to do that ? Thank you for help in advance.

Share Improve this question edited Jan 17, 2014 at 9:14 mounaim asked Jan 17, 2014 at 8:58 mounaimmounaim 1,1808 gold badges32 silver badges63 bronze badges 2
  • css :hover have you tried? – micnic Commented Jan 17, 2014 at 9:01
  • Yes micnic :) I've tried the answer provided by @Midhum but it's not working on IE8 :/ – mounaim Commented Jan 17, 2014 at 9:33
Add a ment  | 

5 Answers 5

Reset to default 6

You can do all of this with CSS. Play around with CSS triangles for the tooltip but what you're mainly looking for is to use the :hover pseudo-class. No need for Javascript.

.input {
    position: relative;
}

.tooltip {
    display: none;
    padding: 10px;
}

.input:hover .tooltip {
    background: blue;
    border-radius: 3px;
    bottom: -60px;
    color: white;
    display: inline;
    height: 30px;
    left: 0;
    line-height: 30px;
    position: absolute;
}

.input:hover .tooltip:before {
    display: block;
    content: "";
    position: absolute;
    top: -5px;
    width: 0; 
    height: 0; 
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid blue;
}

http://jsfiddle/v8xUL/1/

You can use Jquery Tooltip:

Jquery Tooltip

Just one more way to do that...

Filldle Demo

For me in IE8 OK DEMO

<input type="text">
<span>Some Text inside... </span>




span {
        background-color: rgba(0,102,255,.15);
        border: 2px solid rgba(0,102,255,.5);
        border-radius: 10px;
        color: #000;
        display: none;
        padding: 10px;
        position: relative;
    }

span:before {
    content: "";
    border-style: solid;
    border-width: 0 15px 15px 15px;
    border-color:  transparent transparent rgba(0,102,255,.5) transparent;
    height: 0;
    position: absolute;
    top: -17px;
    width: 0;
}

input {
    display: block
}

input:hover + span {
    display: inline-block;
    margin: 10px 0 0 10px
}
* simple css-based tooltip */
.tooltip {
    background-color:#000;
    border:1px solid #fff;
    padding:10px 15px;
    width:200px;
    display:none;
    color:#fff;
    text-align:left;
    font-size:12px;

    /* outline radius for mozilla/firefox only */
    -moz-box-shadow:0 0 10px #000;
    -webkit-box-shadow:0 0 10px #000;
}
 // select all desired input fields and attach tooltips to them
      $("#myform :input").tooltip({

      // place tooltip on the right edge
      position: "center right",

      // a little tweaking of the position
      offset: [-2, 10],

      // use the built-in fadeIn/fadeOut effect
      effect: "fade",

      // custom opacity setting
      opacity: 0.7

      });

got to this link http://jquerytools/demos/tooltip/form.html

Try this property it's asp but may work for your case

ErrorMessage="Your Message";

发布评论

评论列表(0)

  1. 暂无评论