我需要做一个内部有箭头和渐变的圆圈。我知道我可以把它当作图像来使用。但它需要在屏幕大小调整上灵活,以便背景梯度将动态变化。我很好奇是否可以使用单个<span>标签和CSS来实现这一点。


发布于 2011-12-24 23:47:29
编辑:

下面是一个使用两个div来模拟使用旋转和边界半径的箭头的示例:
.btn{
cursor:pointer;
position:relative;
font-family:'Trebuchet MS', Verdana, Arial, sans-serif;
display:inline-block;
padding:3px 0 3px 16px;
text-align:center;
height:22px;
color:#696969;/*#DB7DB4;*/
text-shadow:0px 1px 1px #fff;
-webkit-border-radius: 22px;
-moz-border-radius: 22px;
border-radius: 22px;
border:1px solid rgba(220,87,166,0.8);
box-shadow: 0px 0px 0px 3px rgba(220,87,166, 0.8);
background: #fafafa; /* Old browsers */
background: -moz-linear-gradient(top, #fafafa 0%, #939393 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fafafa), color-stop(100%,#939393)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #fafafa 0%,#939393 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #fafafa 0%,#939393 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #fafafa 0%,#939393 100%); /* IE10+ */
background: linear-gradient(top, #fafafa 0%,#939393 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fafafa', endColorstr='#939393',GradientType=0 ); /* IE6-9 */
}
.btn_circle{
position:relative;
float:right;
margin:0px 3px 0 8px;
display:table;
width:20px;
height:21px;
border:1px solid rgba(255,255,255,0.6);
border-radius:21px;
box-shadow: inset 0px 3px 2px rgb(92, 38, 70);
background: #6b294f; /* Old browsers */
background: -moz-linear-gradient(top, #6b294f 0%, #BE609E 99%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6b294f), color-stop(99%,#BE609E)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #6b294f 0%,#aa6592 99%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #6b294f 0%,#BE609E 99%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #6b294f 0%,#BE609E 99%); /* IE10+ */
background: linear-gradient(top, #6b294f 0%,#BE609E 99%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6b294f', endColorstr='#aa6592',GradientType=0 ); /* IE6-9 */
}
.btn_arr{
position:absolute;
right:8px;
height:3px;
width:10px;
background:#d9d9d9;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
box-shadow:-1px 0px 1px #6F375D;
}
.btn_top{
top:11px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
}
.btn_bot{
top:16px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transform: rotate(-45deg);
}老帖子:

以下是唯一可能的(AFAIK) css箭头的示例:
HTML:
<div class="circle">
<div class="arrow"></div>
</div>CSS:
.arrow{
margin:0 auto;
width: 0;
height: 0;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-left: 8px solid #CFC5CD;
}
.circle{
display:table;
line-height:30px;
width:10px;
height:10px;
padding:3px 5px 3px 7px;
border:2px solid #CFC5CD;
border-radius:21px;
background: #6b294f; /* Old browsers */
background: -moz-linear-gradient(top, #6b294f 0%, #aa6592 99%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6b294f), color-stop(99%,#aa6592)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #6b294f 0%,#aa6592 99%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #6b294f 0%,#aa6592 99%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #6b294f 0%,#aa6592 99%); /* IE10+ */
background: linear-gradient(top, #6b294f 0%,#aa6592 99%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6b294f', endColorstr='#aa6592',GradientType=0 ); /* IE6-9 */
}发布于 2011-12-25 00:00:01
大致是这样的,
http://jsfiddle.net/charlescarver/kuGSw/
就像你说的,它用的就是,
<a class="link" href="#">
<span>Link</span>
</a>然后css看起来像这样,
.link{
background: rgb(255,255,255); /* Old browsers */
background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(148,146,149,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(148,146,149,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(148,146,149,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(148,146,149,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(148,146,149,1) 100%); /* IE10+ */
background: linear-gradient(top, rgba(255,255,255,1) 0%,rgba(148,146,149,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#949295',GradientType=0 ); /* IE6-9 */
padding:10px 15px;
border-radius:10px;
box-shadow:inset 0 -1px 0 #935E7A;
border-width: 0px 33px 0px 0px;
-moz-border-image: url(http://i.imgur.com/Eepyg.png) 0 33 0 33 stretch;
-webkit-border-image: url(http://i.imgur.com/Eepyg.png) 0 33 0 33 stretch;
-o-border-image: url(http://i.imgur.com/Eepyg.png) 0 33 0 33 stretch;
border-image: url(http://i.imgur.com/Eepyg.png) 0 33 0 33 stretch;
}
a{
text-decoration:none;
color:#935E7A;
}我很确定它是跨浏览器的,但我不确定border-image。您可以使用@roXon的代码,创建第二个span,然后将其定位到文本的右侧。这只使用了一个图像。
发布于 2011-12-25 00:00:36
输出:

尝试使用不同的字体或unicode字符,以获得所需的箭头外观。
标记:
<span></span>CSS:
span {
/* Base size, adjustable */
font-size:20px;
display:block;
border-radius: 4em;
padding:1em;
width:1em;
height:1em;
color:#fff;
text-shadow:0 0 .25em #000;
background: #60224b;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#60224b), to(#c45e9f));
background: -webkit-linear-gradient(#60224b, #c45e9f);
background: -moz-linear-gradient(#60224b, #c45e9f);
background: -ms-linear-gradient(#60224b, #c45e9f);
background: -o-linear-gradient(#60224b, #c45e9f);
background: linear-gradient(#60224b, #c45e9f);
border:.1em solid #ccc;
}
span:after {
content:">";
font-size:2.5em;
position:relative;
/* A little adjustment */
top:-.4em;
font-weight:900;
}https://stackoverflow.com/questions/8625354
复制相似问题