【发布时间】:2013-10-07 08:47:08
【问题描述】:
我正在尝试用 html/css 创建这个形状:
我的要求是:
- 正文背景可能会因页面而异,因此不能使用 alpha 遮罩图像
- 悬停时背景颜色可转换
- 形状的所有角都是圆形的
如果有尖角,你可以用 css 三角形来做,但圆角给我带来麻烦。
到目前为止我在 HTML 中拥有的内容:
<ul class="tags">
<li><a href="#">Lorem</a></li>
<li><a href="#">Ipsum</a></li>
<li><a href="#">Longer text in tag</a></li>
<li><a href="#">Dolor</a></li>
</ul>
在 CSS 中:
.tags {
list-style: none;
margin: 0;
padding: 1em;
}
.tags li {
display: inline-block;
margin-right: 2em;
position: relative;
}
.tags a {
background: #283c50;
color: #fff;
display: block;
line-height: 1em;
padding: 0.5em;
text-decoration: none;
-webkit-border-radius: 10px 0 0 10px;
-moz-border-radius: 10px 0 0 10px;
border-radius: 10px 0 0 10px;
-webkit-transition: background 200ms ease;
-moz-transition: background 200ms ease;
-o-transition: background 200ms ease;
-ms-transition: background 200ms ease;
transition: background 200ms ease;
}
.tags a:before {
background: #283c50;
content: "";
height: 1.75em;
width: 1.75em;
position: absolute;
top: 0.1em;
right: -0.87em;
z-index: -1;
-webkit-transform: rotate(40deg);
-moz-transform: rotate(40deg);
-o-transform: rotate(40deg);
-ms-transform: rotate(40deg);
transform: rotate(40deg);
-webkit-border-radius: 0.625em;
-moz-border-radius: 0.625em;
-o-border-radius: 0.625em;
-ms-border-radius: 0.625em;
border-radius: 0.625em;
-webkit-transition: background 200ms ease;
-moz-transition: background 200ms ease;
-o-transition: background 200ms ease;
-ms-transition: background 200ms ease;
transition: background 200ms ease;
}
.tags a:hover,
.tags a:hover:before {
background: #1eaa82;
}
它只在 Chrome 上看起来不错。对于其他人来说,三角形位置存在差异,或者三角形和实际标签在不同时间发生过渡。见例子http://jsfiddle.net/hfjMk/1/
这甚至可能/可行吗?还是我必须放弃过渡并为三角形部分使用图像?
【问题讨论】:
-
我真的看不出 Chrome 和其他的有多大区别。编辑:哦,歌剧。哦,好吧。
-
我觉得这可能比尝试使用纯 CSS 在所有浏览器、移动设备等中看起来都不错的做法更麻烦。我可能会考虑使用一个图像系统,它允许您拥有始终看起来很棒的自动扩展标签。
标签: html css shapes css-shapes