我有一个纯 CSS 驱动的工具提示,但它不能动态定位。如果下方空间很小或没有空间,我希望工具提示显示在顶部,反之亦然。知道怎么做吗?我知道我需要 Javascript 或 jQuery 来实现,但我对脚本没有太多想法。
这是CSS代码:
a.tooltipdrop {
outline:none;
font-family:Arial;
}
a.tooltipdrop strong {
line-height:30px;
}
a.tooltipdrop:hover {
text-decoration:none;
}
a.tooltipdrop span {
z-index:10;
display:none;
padding:14px 10px;
margin-top:-30px;
margin-left:18px;
width:450px;
line-height:18px;
}
a.tooltipdrop:hover span{
display:inline;
position:absolute;
color:#111;
border:3px solid #E51427;
background:#fffAF0;
font-family:arial;
font-size: 14px;
}
.callout {
z-index:20;
position:absolute;
top:30px;
border:0;
left:-12px;
}
/*CSS3 extras*/
a.tooltipdrop span
{
border-radius:4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
}
table{
border-collapse:collapse;
}
table, td, th{
border:0;
font-family:Arial;
font-style:normal;
font-size:12px;
}
td{
padding: 0 5px 8px;
}
.tdHeader{
font-weight: bold;
}
HTML 代码:
<a href="#" class="tooltipdrop">See schedule
<span>
<img class="callout" src="tooltipdrop.gif" />
<strong>Cancellation Policy</strong><br />
The last day to drop without penalty is 08/13/2013. The following charges will be applied after this date: <br/><br/>
<table>
<tr>
<td class="tdHeader">Cancellation Dates</td>
<td class="tdHeader">Late Charge</td>
<td class="tdHeader">Charge amount if paid in full:</td>
</tr>
<tr>
<td>10/05/2013 - 10/11/2013</td>
<td>10.0% </td>
<td>$50.00</td>
</tr>
<tr>
<td>10/12/2013 - 10/16/2013 </td>
<td>25.0%</td>
<td>$125.00</td>
</tr>
<tr>
<td>10/17/2013 - 10/18/2013</td>
<td>50.0%</td>
<td>$250.00</td>
</tr>
<tr>
<td>10/19/2013 - 10/19/2013</td>
<td>100.0%</td>
<td>$500.00</td>
</tr>
</table>
</span>
</a>