【问题标题】:Tooltip/Speech bubble with a gradient background and arrow at top-center带有渐变背景和顶部中心箭头的工具提示/语音气泡
【发布时间】:2015-05-17 22:26:07
【问题描述】:

我有这个形状:

我想知道是否可以使用 CSS3 创建它。

This is what I have so far (click for fiddle):

HTML:

<div id="cafeDialog" role="dialog" class="cafeDialog caspSearch" style="">
    <div data-title="Search" role="main">
        <div>

        </div>
    </div>
</div>

CSS:

html, body {
    height: 100%;
}
.caspSearch {
    border: 1px solid black;
    background: black;
   background: -moz-linear-gradient(top, rgba(128, 144, 152, 0.9) 0%, rgba(67, 74, 80, 0.91) 8%, rgba(54, 58, 61, 0.96) 91%, rgba(74, 81, 85, 0.9) 100%);
    /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(128, 144, 152, 0.9)), color-stop(8%, rgba(67, 74, 80, 0.91)), color-stop(91%, rgba(54, 58, 61, 0.96)), color-stop(100%, rgba(74, 81, 85, 0.9)));
    /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(128, 144, 152, 0.9) 0%, rgba(67, 74, 80, 0.91) 8%, rgba(54, 58, 61, 0.96) 91%, rgba(74, 81, 85, 0.9) 100%);
    /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(128, 144, 152, 0.9) 0%, rgba(67, 74, 80, 0.91) 8%, rgba(54, 58, 61, 0.96) 91%, rgba(74, 81, 85, 0.9) 100%);
    /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(128, 144, 152, 0.9) 0%, rgba(67, 74, 80, 0.91) 8%, rgba(54, 58, 61, 0.96) 91%, rgba(74, 81, 85, 0.9) 100%);
    /* IE10+ */
    background: linear-gradient(to bottom, rgba(128, 144, 152, 0.9) 0%, rgba(67, 74, 80, 0.91) 8%, rgba(54, 58, 61, 0.96) 91%, rgba(74, 81, 85, 0.9) 100%);
    /* W3C */
    width: 500px;
    height: 300px;
    border-radius: 10px;
    padding: 0 !important;
    position:relative;
    top: 30px;

}
.caspSearch:before {
    content:'';
    width: 0;
    height: 0;
    display: block;
    position: absolute;
    border-bottom: 50px solid white;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
}

我正在努力处理三角形,因为它需要透明渐变,黑色边框需要包裹它。

【问题讨论】:

    标签: html css css-shapes


    【解决方案1】:

    这是你要找的吗?

    CSS

    .triangle-isosceles {
        height: 200px;
        width: 300px;
        position:relative;
        padding:15px;
        margin:1em 0 3em;
        color:#000;
        background:#f3961c;
        background:-webkit-gradient(linear, 0 0, 0 100%, from(#f9d835), to(#f3961c));
        background:-moz-linear-gradient(#f9d835, #f3961c);
        background:-o-linear-gradient(#f9d835, #f3961c);
        background:linear-gradient(#f9d835, #f3961c);
        -webkit-border-radius:10px;
        -moz-border-radius:10px;
        border-radius:10px;
    }
    
    .triangle-isosceles.top {
        background:-webkit-gradient(linear, 0 0, 0 100%, from(#f3961c), to(#f9d835));
        background:-moz-linear-gradient(#f3961c, #f9d835);
        background:-o-linear-gradient(#f3961c, #f9d835);
        background:linear-gradient(#f3961c, #f9d835);
    }
    
    .triangle-isosceles:after {
        content:"";
        position:absolute;
        bottom:-15px; 
        left:50px;
        border-width:15px 15px 0;
        border-style:solid;
        border-color:#f3961c transparent;
        display:block; 
        width:0;
    }
    
    .triangle-isosceles.top:after {
        top:-15px;
        right:50px; 
        bottom:auto;
        left:auto;
        border-width:0 15px 15px;
        border-color:#f3961c transparent;
    }
    

    HTML

    <p class="triangle-isosceles top">Your content.</p>
    

    小提琴

    http://jsfiddle.net/sjccN/4/

    【讨论】:

    • 如果我使用带方向的渐变就不会美了。示例线性梯度(143deg,#EBD584 0%,#DDAE00 100%)
    【解决方案2】:

    我为你做了一个样本......只需将你的阴影等添加到这个和你的集合中:)

    http://jsfiddle.net/BNgTh/

    #talkbubble {
       width: 120px;
       height: 80px;
        margin-top:20px;
        margin-left:40px;
       background: red;
       position: relative;
       -moz-border-radius:    10px;
       -webkit-border-radius: 10px;
       border-radius:         10px;
    }
    #talkbubble:before {
       content:"";
       position: absolute;
       top: -20px;
        left:40%;
       width: 0;
       height: 0;
       border-bottom: 26px solid red;
       border-right: 13px solid transparent;
       border-left: 13px solid transparent;
    }
    

    更改 #talkbubble:before 中的顶部值,使其也变得更小。

    【讨论】:

    • 感谢您的努力,但您的问题错了,我知道如何创建和定位三角形,问题是如何给它一个渐变和不透明度,因为您不能用边框来做。
    • 我可以问为什么不用图像来代替三角形?因为我不知道它是否可能只使用 css 来获得正确的边框......
    • 使用图像绝对是一种选择,只是认为使用纯 CSS 可能是可行的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 2019-05-26
    相关资源
    最近更新 更多