开发者

Is it possible to make a box arrow in css 3 with a gradient

If you look at the link below, you will see a floating green box with the arrow pointing left:

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

Can this be done using only CSS3? Is it possible to make the arrow shape and have a gradient that is both in the box and the arrow? If so, how 开发者_JS百科would you do this?

Thanks


This is close: http://jsfiddle.net/8RuB6/1/

Tested in IE9 and recent versions of 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 */
}


This was the closest I could get with pure css and HTML... the only problem is the arrow tip which can't use the gradient.

<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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜