如何在CSS

时间:2015-12-08 22:47:11

标签: html css

我想知道用CSS实现这种设计是否可行?我想在文本之后创建一个div或span元素,然后将它制作一个只有两个彩色边框然后将其旋转45度的盒子?否则,我只想使用图片精灵。

enter image description here

2 个答案:

答案 0 :(得分:3)

你可以使用这样的CSS:



.caret.caret-reversed {
  border-bottom: 10px solid #000000;
  border-left: 6px solid rgba(0, 0, 0, 0);
  border-right: 6px solid rgba(0, 0, 0, 0);
  content: "";
  display: inline-block;
  height: 0;
  vertical-align: top;
  width: 0;
  transform: rotate(180deg);
}

<span class="caret caret-reversed"></span>
&#13;
&#13;
&#13;

将解决方案的border-bottom颜色更改为#fff

或者使用pseudo类的另一种方式:

&#13;
&#13;
body {
  background-color: #003;
  font-family: verdana;
  font-size: 10pt;
}
a {
  color: #003;
  background-color: #fff;
  text-decoration: none;
  display: inline-block;
  padding: 5px;
  position: relative;
  z-index: 2;
  border: 1px solid #f33;
}
a:after,
a:before {
  top: 100%;
  left: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}
a:after {
  border-color: transparent;
  border-top-color: #fff;
  border-width: 5px;
  margin-left: -5px;
}
a:before {
  border-color: rgba(0, 0, 51, 0);
  border-top-color: #003;
  border-width: 6px;
  margin-left: -6px;
}
&#13;
<a href="#" class="link">Performance</a>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

&#13;
&#13;
body {
  background: #111842
}
li {
  width: 100px;
  display: inline-block;
  border: 1px solid #000;
  height: 30px;
  line-height: 30px;
  text-align: center;
  position: relative;
  z-index: 10;
  background: #111842;
  border: 1px solid #f19d47;
}
li a {
  color: #fff;
  text-decoration: none;
}
li:after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 1px;
  z-index: 15;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid #f19d47;
}
li:before {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 1px;
  z-index: 20;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #111842;
}
li.active {
  background: #fff;
  border: 1px solid #fff;
}
.active a {
  color: #000;
}
li.active:after,
li.active:before {
  content: '';
  border-top: 10px solid #fff;
}
&#13;
<ul>
  <li class="active"><a href="#">One</a>
  </li>
  <li><a href="#">One</a>
  </li>
  <li><a href="#">One</a>
  </li>
  <li><a href="#">One</a>
  </li>
  <ul>
&#13;
&#13;
&#13;