是否可以使用渐变在css 3中制作一个方框箭头

时间:2011-08-05 01:37:11

标签: css html5 gradient css3

如果您查看下面的链接,您会看到一个浮动的绿色框,箭头指向左侧:

http://dribbble.com/shots/107845-hover-button

这可以仅使用CSS3吗?是否可以使箭头形状并且具有框和箭头中的渐变?如果是这样,你会怎么做?

由于

2 个答案:

答案 0 :(得分:7)

这很接近:http://jsfiddle.net/8RuB6/1/

在IE9和最新版本的Firefox,Chrome,Safari,Opera中测试。

<强> HTML:

<span class="tooltip">Hover me</span>

<强> CSS:

.tooltip {
    position: relative;
    display: inline-block;
    font: 13px sans-serif;
    height: 60px;
    line-height: 60px;
    border: 1px solid #444
}
.tooltip:hover:before {
    content: 'Add new authorisation';
    position: absolute;
    z-index: 1;
    top: 50%;
    margin-top: -15px;
    left: 100%;
    margin-left: 20px;
    height: 30px;
    line-height: 30px;
    padding: 0 9px 0 3px;
    white-space: nowrap;
    color: #fff;
    font-weight: bold;

    -webkit-border-top-right-radius: 5px;
    -webkit-border-bottom-right-radius: 5px;
    -moz-border-radius-topright: 5px;
    -moz-border-radius-bottomright: 5px;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px; 

    background: #3b679e; /* Old browsers */
    background: -moz-linear-gradient(top, #3b679e 0%, #2b88d9 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3b679e), color-stop(50%,#2b88d9), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* Opera11.10+ */
    background: -ms-linear-gradient(top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3b679e', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
    background: linear-gradient(top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* W3C */
}
.tooltip:hover:after {
    content: ' ';
    position: absolute;
    top: 50%;
    margin-top: -15px;
    left: 100%;
    margin-left: 20px;
    width: 21px;
    height: 21px;
    background: #ccc;
    -webkit-transform: rotate(45deg);
    -webkit-transform-origin: 0 0;
    -moz-transform: rotate(45deg);
    -moz-transform-origin: 0 0;
    -o-transform: rotate(45deg);
    -o-transform-origin: 0 0;
    -ms-transform: rotate(45deg);
    -ms-transform-origin: 0 0;
    transform: rotate(45deg);
    transform-origin: 0 0;

    background: #3b679e; /* Old browsers */
    background: -moz-linear-gradient(left top, #3b679e 0%, #2b88d9 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,#3b679e), color-stop(50%,#2b88d9), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(left top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(left top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* Opera11.10+ */
    background: -ms-linear-gradient(left top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3b679e', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
    background: linear-gradient(left top, #3b679e 0%,#2b88d9 50%,#207cca 51%,#7db9e8 100%); /* W3C */
}

答案 1 :(得分:1)

这是我用纯css和HTML得到的最接近的...唯一的问题是箭头提示不能使用渐变。

<div class="arrow"></div><div class="content">Add new authorization</div>


.arrow
{
    width:2px;
    height:2px;
    border: 12px inset black;
    border-right-width: 8px;
    border-color: transparent #5a0 transparent transparent;
}
.content
{
    background-color: green;
    padding:2px 8px 2px 4px;
    border: 1px solid #490;
    border-left-width: 0px;
    background-image: -webkit-linear-gradient(top, #8c0, #070);
    text-shadow: 1px 1px #8c0, -1px -1px #070
}
div {float:left; color:white;
}

http://jsfiddle.net/JZaAa/