【问题标题】:CSS modification to arrange pointerCSS修改排列指针
【发布时间】:2012-02-24 09:41:38
【问题描述】:

我的 html 上有一个 css 工具提示。我在气泡底部看到箭头标记(bubble:after)。如何重新排列到气泡的右中心?

这是我的div

 <div class="bubble">Hi there. I like turtles.</div>
<p style="margin-left: 1em;">Mikey sez</p>

我的 div 上显示的气泡来自下面的 css

 <style type="text/css">
 .bubble {
 position: relative;
 background-color:#eee;
 margin: 0;
 padding:10px;
 text-align:center;
 width:180px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
-webkit-box-shadow: 0px 0 3px rgba(0,0,0,0.25);
-moz-box-shadow: 0px 0 3px rgba(0,0,0,0.25);
box-shadow: 0px 0 3px rgba(0,0,0,0.25); 
}
.bubble:after {    //This after mark has to be arranged so to point to the right of bubble
position: absolute;  //The position should be at the center
display: block;
content: "";  
border-color: #eee transparent transparent transparent;
border-style: solid;
border-width: 10px;
height:0;
width:0;
position:absolute;
bottom:-19px;
left:1em;
 }

如下图重新排列

【问题讨论】:

    标签: html css styles position


    【解决方案1】:

    查看this jsFiddle。您需要做的就是更改::after 元素的绝对定位,并切换哪个边框有颜色,从这里:

    border-color: blue transparent transparent transparent;
    bottom:-19px;
    left:1em;
    

    到这里:

    border-color: transparent transparent transparent blue;
    bottom:25%;
    right:-19px;
    

    【讨论】:

    • 此解决方案可能适用于特定情况,但如果您决定增加 bubble 大小或填充布局将会中断。
    【解决方案2】:

    这样就可以了,http://jsfiddle.net/elclanrs/hu38A/1

    .bubble:after {
        content: "";
        position: absolute;
        border-color: transparent transparent transparent red;
        border-style: solid;
        border-width: 10px;
        height: 0;
        width: 0;
        top: 50%;
        margin-top: -10px; /* border-width */
        right: -20px; /* border-width*2; */
    }
    

    【讨论】:

    • 那并不完全正确。这将锚定位在中心。我需要它在气泡的右侧和 v-align 中心。
    • @oneofthelions 而不是只是复制和粘贴代码,您应该自己添加并尝试理解它。它不起作用的原因是 cmets 没有针对 CSS 进行转义。
    • 这正是它的作用。刚刚将它粘贴在这里,它工作得很好jsfiddle.net/elclanrs/hu38A/1。我修复了 JS fomart 中的 cmets,这可能是问题所在。正如我的头疼所说,最好还是自己写。您将通过这种方式了解更多信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 2013-04-06
    • 2021-04-09
    • 2015-08-01
    • 1970-01-01
    相关资源
    最近更新 更多