简体   繁体   English

如何将巨大的 html 和引导代码(卡)放入工具提示中?

[英]How to put huge html and bootstrap code (card) inside tooltip?

I'm trying to make a system, where active users is shown in page, and when you hover on his name, you can see tooltip with bootstrap's card in it.我正在尝试制作一个系统,在页面中显示活动用户,当您在他的名字上显示 hover 时,您可以看到带有引导程序卡的工具提示。 But when I put card code inside tooltip it messes up.但是当我将卡片代码放在工具提示中时,它就搞砸了。

Code:代码:

function displayUsersMainPage() {
    $output = '';
    $count = 0;
    $result = getUsersMainPage();
    while($row = mysqli_fetch_assoc($result)) {
        $output .= '<b data-toggle="tooltip" data-placement="top" title="<div class="card" style="width: 18rem;">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the cards content.</p>
    <a href="#" class="card-link">Card link</a>
    <a href="#" class="card-link">Another link</a>
  </div>
</div>">
  '.$row["username"].'
</b>';

        $count = $count + 1;
    }
    return $output; 
}

You need to replace all your nested quotes with HTML entities ( &quot; ) before it will work.您需要将所有嵌套引号替换为 HTML 实体 ( &quot; ) 才能正常工作。 Once you've done that it will be valid.一旦你这样做了,它将是有效的。 However, you should note that the browser's tooltip will not render the HTML but instead will display the markup as text.但是,您应该注意浏览器的工具提示不会呈现 HTML 而是将标记显示为文本。 If you want a tooltip with custom formatting you'll need to either roll your own or use a preroll (framework) of some kind.如果您想要一个具有自定义格式的工具提示,您需要自己滚动或使用某种预滚动(框架)。 Either way, I recommend using a <div> instead of the <b> tag, placing your content inside it instead of in an attribute, and adjusting the display and positioning with CSS.无论哪种方式,我都建议使用<div>而不是<b>标记,将内容放在其中而不是属性中,并使用 CSS 调整显示和定位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM