Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a box when mouse over text in pure CSS?

Tags:

I have tried many times to do this, but it has not worked out yet.

When I mouse over this text

enter image description here

Then it must show me this box

enter image description here

I want to achieve this effect purely with CSS if anybody can do this.

like image 711
Rohit Azad Malik Avatar asked Apr 20 '12 09:04

Rohit Azad Malik


People also ask

How do you make a hover text box in HTML?

HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .

How do I keep text in a box CSS?

CSS word-wrap property is used to break the long words and wrap onto the next line. This property is used to prevent overflow when an unbreakable string is too long to fit in the containing box. This property defines the breaks in the word to avoid the overflow when a word is too long to fit in the container.

How do I make text hover?

There are two ways you can create a hover text for your HTML elements: Adding the global title attribute for your HTML tags. Creating a tooltip CSS effect using :before selector.


1 Answers

You can write like this:

CSS

span{     background: none repeat scroll 0 0 #F8F8F8;     border: 5px solid #DFDFDF;     color: #717171;     font-size: 13px;     height: 30px;     letter-spacing: 1px;     line-height: 30px;     margin: 0 auto;     position: relative;     text-align: center;     text-transform: uppercase;     top: -80px;     left:-30px;     display:none;     padding:0 20px;  } span:after{     content:'';     position:absolute;     bottom:-10px;     width:10px;     height:10px;     border-bottom:5px solid #dfdfdf;     border-right:5px solid #dfdfdf;     background:#f8f8f8;     left:50%;     margin-left:-5px;     -moz-transform:rotate(45deg);     -webkit-transform:rotate(45deg);     transform:rotate(45deg); } p{     margin:100px;     float:left;     position:relative;     cursor:pointer; }  p:hover span{     display:block; } 

HTML

<p>Hover here<span>some text here ?</span></p> 

Check this http://jsfiddle.net/UNs9J/1/

like image 102
sandeep Avatar answered Oct 08 '22 21:10

sandeep