您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

带有百分比宽度的自适应CSS三角形

带有百分比宽度的自适应CSS三角形

您可以使用倾斜和旋转的伪元素在链接下创建一个

三角形通过padding-bottom属性保持其长宽比。

如果您希望形状根据其内容来适应其大小,则可以删除.btn类的宽度

.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-@R_714_2419@;

  overflow: hidden;

}

.btn:after {

  content: "";

  position: absolute;

  top:50px;  left: 0;

  background-color: inherit;

  padding-bottom: 50%;

  width: 57.7%;

  z-index: -1;

  transform-origin: 0 0;

  transform: rotate(-30deg) skewX(30deg);

}

/** FOR THE DEMO **/



body {

  background: url('http://i.imgur.com/qi5fget.jpg');

  background-size: cover;

}


<a href="#" class="btn">Hello!</a>
CSS 2022/1/1 18:17:55 有509人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶