Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create tag shape with css

Tags:

html

css

I'm trying to create a tag shape with the css only so that it looks like:

enter image description here

I'm trying following but unable to use the border for the triangle area.

HTML:

<a href="#">Test</a>

CSS:

a{
    float: left;
    height: 35px;
    position:relative;  
    border: 1px solid red;
    border-right: none; 
    width: 100px;
} 

a:before{
    content: "";
    position: absolute;
    top: -1px;
    right: -18px;
    width: 0;
    height: 0;
    border-color: white white white red;
    border-style: solid;
    border-width: 19px 0 18px 18px; 
}

JSFiddle: http://jsfiddle.net/Sac3m/

like image 876
user966582 Avatar asked Dec 22 '25 10:12

user966582


2 Answers

You could rotate a square instead, although i doubt the results will be great cross-browser

Modified code:

a {
  float: left;
  height: 35px;
  position: relative;
  border: 1px solid red;
  border-right: none;
  width: 100px;
}

a:after {
  content: "";
  position: absolute;
  top: 4px;
  right: -13px;
  width: 25px;
  height: 25px;
  border: 1px solid red;
  border-left: none;
  border-bottom: none;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  transform: rotate(45deg);
}
<a></a>

(Latest IE, Firefox and Chrome seems OK with it)


Update

If you need IE8 support, you could try to put a white triangle on top of the (original) red triangle:

a {
  float: left;
  height: 36px;
  position: relative;
  border: 1px solid red;
  border-right: none;
  width: 100px;
}

a:before {
  content: "";
  position: absolute;
  top: -1px;
  right: -18px;
  width: 0;
  height: 0;
  border-color: white white white red;
  border-style: solid;
  border-width: 19px 0 19px 19px;
}

a:after {
  content: "";
  position: absolute;
  top: 0;
  right: -17px;
  width: 0;
  height: 0;
  border-color: transparent transparent transparent white;
  border-style: solid;
  border-width: 18px 0 18px 18px;
}
<a></a>
like image 169
xec Avatar answered Dec 24 '25 04:12

xec


The below code helps to create a tag shape. It works in all major browsers.

#swc {
  position: relative;
  margin: 0 5px 0 10px;
  display: inline-block;
  height: 66px;
  padding: 0 35px 0 20px;
  font-size: 25px;
  line-height: 65px;
  cursor: pointer;
  font-weight: 100;
  margin: 20px 25px;
  background: #f3f3f3;
  transition: background 0.3s;
}

#swc:after {
  position: absolute;
  content: "";
  right: -19px;
  width: 1px;
  height: 0px;
  border-left: 18px solid #f3f3f3;
  border-top: 33px solid transparent;
  border-bottom: 33px solid transparent;
  transition: border 0.3s;
}

#swc:hover {
  background: green;
  color: #ffffff;
}

#swc:hover:after {
  border-left-color: green;
}
<span class="pricetag-right" id="swc">Tag Content!</span>
like image 37
M. Lak Avatar answered Dec 24 '25 02:12

M. Lak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!