1

Hello i would like to style the borders of my list element so that the border-top-right and the border-bottom-right meet in a triangular shape with only css.

like so: enter image description here

enter image description here

or like so: I want to achieve both of these two shapes using css alone, to maybe alter the borders to that shape, i would like to know if that is possible and how i can go about it. The element in question is a list element.

Blank EDjok
  • 732
  • 2
  • 14
  • 33

3 Answers3

2

If you're after that specific shape, you can use the :before and :after pseudo elements

Demo Fiddle (second 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;
}
SW4
  • 69,876
  • 20
  • 132
  • 137
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;
}
Community
  • 1
  • 1
rafaelcastrocouto
  • 11,781
  • 3
  • 38
  • 63
1

code for your shapes:-

#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;
}
akshay koli
  • 311
  • 1
  • 10
  • thank you, your answer worked well for me, but could you show me how to remove the thin line right before the triangle? I know it shows in the picture i posted but i would like to remove that line. :) – Blank EDjok May 12 '14 at 12:23