Css for:三角形之后

时间:2017-04-27 11:22:29

标签: css css-preprocessor

Image from github

Github使用两个::after元素来显示三角形周围的绿色边框。

像这样:

dom

只使用一个::after选择器,我能得到相同的结果吗? 我想知道这样的事情是否可能。

2 个答案:

答案 0 :(得分:1)

您可以尝试

div {
  width:300px;
  height:100px;
  background:#fff;
  border:1px solid green;
  position:relative;
  padding:20px;
 }
 
 div:after {
  content:"";
  position:absolute;
  right:-11px;
  top:30px;
  width:20px;
  height:20px;
  background:#fff;
  border:1px solid green;
  border-left:none;
  border-bottom:none;
  transform:rotate(45deg);
  -webkit-transform:rotate(45deg);
  user-select:none;
  -webkit-user-select: none;
}
<div>
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
  veniam,quis nostrud exercitation 
</div>

答案 1 :(得分:0)

您可以使用:after&amp; {/ 1>的:before选择器

&#13;
&#13;
div {
  width: 300px;
  height: 200px;
  background: #fff;
  border: 1px solid #1db73f;
  position: relative;
  padding: 20px;
  border-radius:5px;
}
div:before {
  content: "";
  position: absolute;
  right: -20px;
  top: 30px;
  width: 0; 
  height: 0; 
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
  border-left: 20px solid #fff;
  z-index:1;
}
div:after {
  content: "";
  position: absolute;
  right: -21px;
  top: 30px;
  width: 0; 
  height: 0; 
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;      
  border-left: 20px solid #1db73f;
}
&#13;
<div>
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
  quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
  consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
  cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
  proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
&#13;
&#13;
&#13;