我使用jQuery UI的新Tooltip,但是在设置提示框的最大宽度时遇到了麻烦。我猜想应该使用position来完成,但具体怎么做呢?
根据Senni的回答,我把以下内容添加到了一个单独的CSS文件中:
div.ui-tooltip {
max-width: 400px;
}
顺带一提:确保你的独立CSS文件在ui-css之后,否则它将没有效果。否则,你也可以使用!important标记。
$(".selector").tooltip({
open: function (event, ui) {
ui.tooltip.css("max-width", "400px");
}
});
在脚本中:
$(elm).tooltip({tooltipClass: "my-tooltip-styling" });
在CSS中:.my-tooltip-styling {
max-width: 600px;
}
您可以使用 tooltipClass 参数指定一个额外的CSS类,而不是直接修改或覆盖jQuery UI CSS类:
工具提示初始化
$(function() {
$( document ).tooltip({
items: "tr.dataRow",
tooltipClass: "toolTipDetails", //This param here is used to define the extra style class
content: function() {
var element = $( this );
var details = j$("#test").clone();
return details.html();
}
});
});
然后您需要创建那个样式类。您需要在 jQuery UI CSS 文件之后导入此 CSS 文件。
示例 CSS 样式
该类将默认使模态框宽度为 1200 像素,并在超出此范围时添加水平滚动条。
<style>
.toolTipDetails {
width: 1200px;
max-width: 1200px;
overflow:auto;
}
</style>
顺便提一下:通常不建议使用!important
标签,但在这种情况下可以使用它来确保所需的CSS
得到呈现。
.ui-tooltip
{
/* tooltip container box */
max-width: your value !important;
}
.ui-tooltip-content
{
/* tooltip content */
max-width: your value !important;
}
$("#IDOfToolTip").attr("style", "max-width:30px");
$("#IDOfToolTip").css("max-width", "30px");
.ui-tooltip{
max-width: 800px !important;
width: auto !important;
overflow:auto !important;
}
.ui-tooltip-content{
background-color: #fdf8ef;
}
#idOfBodyTag .ui-tooltip
即可。 - Josh