三角形边框

时间:2014-05-12 11:43:26

标签: css

您好我想设置list元素的边框,以便右上角和右下角以三角形相交,只有css。

像这样: enter image description here

enter image description here

或者像这样: 我想单独使用css来实现这两种形状,可能会改变边框到那个形状,我想知道这是否可能以及我如何去做。有问题的元素是一个列表元素。

3 个答案:

答案 0 :(得分:2)

如果您在该特定形状之后,可以使用:before:after伪元素

Demo Fiddlesecond shape

HTML

<div></div>

CSS

div {
    display:inline-block;
    position:relative;
    height:30px;
    width:50px;
    background:Red;
}
div:before, div:after {
    content:'';
    position:absolute;
    display:inline-block;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 15px 0 15px 26.0px;
}
div:after {
    border-color: transparent transparent transparent red;
    right:-26px;
}
div:before {
    border-color: transparent transparent transparent white;
}

答案 1 :(得分:1)

DEMO

div {
  background: #EF3E36;
  margin: 10px;  
}
.arrow1 {    
  position: relative;
  left: 50px;  
  width: 250px; height: 100px;
}
.arrow1:before {
  display: block;
  content: "";
  width: 0;
  height: 0; 
  position: absolute;  
  left: -50px;
  border: 50px solid #EF3E36;
  border-left: 50px solid transparent;  
  border-right: 0;
}
.arrow1:after {
  display: block;
  content: "";
  background: transparent;
  width: 0;
  height: 0;
  position: absolute;
  left: 250px;
  border: 50px solid transparent;
  border-left: 50px solid #EF3E36;
}
.arrow2 {
  position: relative;
  width: 300px; height: 100px;
}
.arrow2:after {
  display: block;
  content: "";
  background: transparent;
  width: 0;
  height: 0;
  position: absolute;
  left: 300px;
  border: 50px solid transparent;
  border-left: 50px solid #EF3E36;
}

答案 2 :(得分:1)

形状代码: -

#breadcrumbs-two{
  overflow: hidden;
  width: 100%;
}

#breadcrumbs-two li{
  float: left;
  margin: 0 .5em 0 1em;
}

#breadcrumbs-two a{
  background: #ddd;
  padding: .7em 1em;
  float: left;
  text-decoration: none;
  color: #444;
  text-shadow: 0 1px 0 rgba(255,255,255,.5); 
  position: relative;
}

#breadcrumbs-two a:hover{
  background: #99db76;
}

#breadcrumbs-two a::before{
  content: "";
  position: absolute;
  top: 50%; 
  margin-top: -1.5em;   
  border-width: 1.5em 0 1.5em 1em;
  border-style: solid;
  border-color: #ddd #ddd #ddd transparent;
  left: -1em;
}

#breadcrumbs-two a:hover::before{
  border-color: #99db76 #99db76 #99db76 transparent;
}

#breadcrumbs-two a::after{
  content: "";
  position: absolute;
  top: 50%; 
  margin-top: -1.5em;   
  border-top: 1.5em solid transparent;
  border-bottom: 1.5em solid transparent;
  border-left: 1em solid #ddd;
  right: -1em;
}

#breadcrumbs-two a:hover::after{
  border-left-color: #99db76;
}

#breadcrumbs-two .current,
#breadcrumbs-two .current:hover{
  font-weight: bold;
  background: none;
}

#breadcrumbs-two .current::after,
#breadcrumbs-two .current::before{
  content: normal;
}