I have three div's and the "show info" item inside each of them. When user hovering with mouse on the "show info" item he can see some text with additional information that appears above "show info" item. But the additional information in different div's can have different text length. Some information can be short and some long... well that makes a problem that text expand the size of div that wrap the information to the bottom and because of this it covers the "info" item. You can clearly understand the problem in my example when hovering the second div "show info"(subject 2). The main goal is to make text expand size of its wrapper to the top, and not cover the "show info" item.
JSFIDDLE EXAMPLE LINK
$(function(){
$('.hoverinfo').mouseover(function(){
$(this).prepend('<div class="info"></div>');
$('.info').html($(this).attr("data-info"));
$('.info').fadeIn();
}).mouseleave(function(){
$('.info').remove();
});
});
.subject{
width:400px;
height:100px;
background:lightblue;
}
.subject:nth-of-type(2){
background:lightgrey;
}
.subject:nth-of-type(3){
background:lightgreen;
}
.info {
position:absolute;
color:black;
width: 200px;
background-color:lightcyan;
border: solid 2px black;
text-align: center;
margin-top: -30px;
display: none;
}
.hoverinfo {
background:pink;
float:right;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<br><br>
<div class="subject">
<div class="hoverinfo" data-info="The text from subject 1 - OK!">show info(hover it)</div>
<span>subject 1</span>
</div>
<div class="subject">
<div class="hoverinfo" data-info="There is more text inside and this is a problem because text expand div to the bottom - PROBLEM!">show info(HOVER IT)</div>
<span>subject 2 - here is a problem</span>
</div>
<div class="subject">
<div class="hoverinfo" data-info="The text from subject 3 - OK">show info (hover it)</div>
<span>subject 3</span>
</div>