css3 - Responsive CSS triangle with percents width -


the code below create arrow right below <a> element:

jsfiddle

.btn {      position: relative;      display: inline-block;      width: 100px;      height: 50px;      text-align: center;      color: white;      background: gray;      line-height: 50px;      text-decoration: none;  }  .btn:after {      content: "";      position: absolute;      bottom: -10px;      left: 0;      width: 0;      height: 0;      border-width: 10px 50px 0 50px;      border-style: solid;      border-color: gray transparent transparent transparent;     }
<a href="#" class="btn">hello!</a>

the problem have indicate link width arrow of proper size because cannot indicate border width in pixels.

how make responsive triangle percent based?

you use skewed , rotated pseudo element create responsive triangle under link :

demo (resize result window see how reacts)

the triangle maintains it's aspect ratio padding-bottom property.

if want shape adapt it's size according it's content, can remove width on .btn class

.btn {    position: relative;    display: inline-block;    height: 50px; width: 50%;    text-align: center;    color: white;    background: gray;    line-height: 50px;    text-decoration: none;    padding-bottom: 15%;    background-clip: content-box;    overflow: hidden;  }  .btn:after {    content: "";    position: absolute;    top:50px;  left: 0;    background-color: inherit;    padding-bottom: 50%;    width: 57.7%;    z-index: -1;    -webkit-transform-origin: 0 0;    -ms-transform-origin: 0 0;    transform-origin: 0 0;    -webkit-transform: rotate(-30deg) skewx(30deg);    -ms-transform: rotate(-30deg) skewx(30deg);    transform: rotate(-30deg) skewx(30deg);  }  /** demo **/    body {    background: url('http://i.imgur.com/qi5fget.jpg');    background-size: cover;  }
<a href="#" class="btn">hello!</a>

for more info on responsive triangles , how make them, can have @ triangles transform rotate (simple , fancy triangles)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -