逐步偏离中心的Bootstrap工具提示

问题描述 投票:0回答:1

https:/file.coffeeuR5wzGxVezHd.gif。我在使用bootstrap的tooltips时遇到了以下问题逐渐偏离中心这里是我使用的图标代码

{{#each guilds}}
<div class="col-sm-1">
    <a href="/dash/{{this.id}}">
        <div class="gicon">
        {{#if this.icon}}
        <img src="https://cdn.discordapp.com/icons/{{this.id}}/{{this.icon}}" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}"  data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
        {{else}}
        <img src="/public/images/default_guild.png" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}"  data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
        {{/if}}
        </div>
    </a>
</div>
{{/each}}
.gicon {
    transition: ease-in-out 0.2s;
}

.gicon:hover {
    filter: brightness(80%);
}

有谁知道为什么会出现这种情况,如何解决?

css bootstrap-4 handlebars.js
1个回答
1
投票

https:/jsfiddle.netkblau237vx92pnec3

我先把你的例子用jsfiddle编码。 你可以点击这个fiddle,看到工具提示,确实是居中的。 我希望这篇文章能帮助你。 它可以作为一个模型,让工具提示居中。

我把这个图片放在我的文件夹里,叫做 "图片"。 它和脚本中的javascript代码处于类似的水平。

https://jsfiddle.net/kblau237/vx92pnec/3/

脚本

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index6</title>
    <style type="text/css">
        .gicon {
            transition: ease-in-out 0.2s;
        }

            .gicon:hover {
                filter: brightness(80%);
            }
    </style>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.6/handlebars.min.js"></script>

    <script type="text/javascript">
        //credit stack overflow
        $(function () {
            $("body").tooltip({ selector: '[data-toggle=tooltip]' });
            var an_array = [
                { id: 1, name: "Guild Name 1", imgURL: "https://file.coffee/u/R5wzGxVezHd.gif" },
                { id: 2, name: "Guild Name 2", imgURL: "https://file.coffee/u/R5wzGxVezHd.gif" }
            ];
            var source = $("#src").html();
            var template = Handlebars.compile(source);
            $("body").append(template({ guilds: an_array }));
        })
    </script>
</head>
<body>
    Tooltips are centered
    <script type='text/template' id='src'>
        {{#each guilds}}
        <div class="col-sm-1">
            <a href="/dash/{{this.id}}">
                <div class="gicon">
                    @*Changed the order of the images*@
                    {{#if this.icon}}
                    <img src="https://cdn.discordapp.com/icons/{{this.id}}/{{this.icon}}" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}" data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
                    {{else}}
                    <img src="{{imgURL}}" alt="{{this.name}}" class="rounded-circle mt-4" width="75" height="75" id="{{this.id}}" data-toggle="tooltip" data-placement="bottom" title="{{this.name}}">
                    {{/if}}
                </div>
            </a>
        </div>
        {{/each}}
    </script>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.