html - CSS - create a dynamic "tag" shape facing to the right -


i'm trying create "price tag" shape using css, sharper edge facing right. when edge of tag facing left, there's no problem adding text (be short or long), since triangle static , rectangle stretching.

i need create same thing "elastic" right facing triangle, keep using 1 class , not dedicated class each text length.

for both examples please see fiddle.

.pricetag {    position: relative;    margin: 0 5px 0 10px;    display: inline-block;    height: 46px;    padding: 0 35px 0 15px;    background: #e8edf0;    font-size: 20px;    line-height: 41px;  }  .pricetag:after {} .pricetag:before {    position: absolute;    content: "";    left: -15px;    width: 1px;    height: 0px;    border-right: 14px solid #e8edf0;    border-top: 23px solid transparent;    border-bottom: 23px solid transparent;  }  /**********/    .pricetag-right {    position: relative;    margin: 0 5px 0 10px;    display: inline-block;    height: 46px;    padding: 0 35px 0 15px;    background: #e8edf0;    font-size: 20px;    line-height: 41px;  }  .pricetag-right:after {} .pricetag-right:before {    position: absolute;    content: "";    left: 382px;    width: 1px;    height: 0px;    border-left: 14px solid #e8edf0;    border-top: 23px solid transparent;    border-bottom: 23px solid transparent;  }
<span class="pricetag">no problem long text</span>  <br>  <br/>  <span class="pricetag-right">need create new class each length</span>

you need position arrow according right side of tag right property instead of left property :

.pricetag {    position: relative;    margin: 0 5px 0 10px;    display: inline-block;    height: 46px;    padding: 0 35px 0 15px;    background: #e8edf0;    font-size: 20px;    line-height: 41px;  }  .pricetag:before {    position: absolute;    content: "";    left: -15px;    width: 1px;    height: 0px;    border-right: 14px solid #e8edf0;    border-top: 23px solid transparent;    border-bottom: 23px solid transparent;  }  /**********/    .pricetag-right {    position: relative;    margin: 0 5px 0 10px;    display: inline-block;    height: 46px;    padding: 0 35px 0 15px;    background: #e8edf0;    font-size: 20px;    line-height: 41px;  }  .pricetag-right:before {    position: absolute;    content: "";    right: -15px;    width: 1px;    height: 0px;    border-left: 14px solid #e8edf0;    border-top: 23px solid transparent;    border-bottom: 23px solid transparent;  }
<span class="pricetag">no problem long or short text (length auto adjusts)</span>  <br>  <br/>  <span class="pricetag-right">need create new class each length</span>  <br/>  <br/>  <span class="pricetag-right">need create nqsdqsdqsdqsdqsdqsdew class each length</span>


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -