如何用css制作走投无路的按钮?

时间:2017-09-04 13:50:45

标签: css

如何使用纯CSS制作这样的按钮?

enter image description here

这就是我所能做的一切:

.sideMenuButton {
  width: 100px;
  height: 100px;
  background: #6d1a3e;
  position: relative;
  transform: rotate(-90deg);
  border: none;
}

.sideMenuButton:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  border-top: 29px solid #6d1a3e;
  border-left: 29px solid #fff;
  width: 42px;
  height: 0;
}
<button type="button" class="sideMenuButton">X</button>

但它的工作方式不正确

1 个答案:

答案 0 :(得分:3)

快速尝试一下。我希望这可以帮到你。 您可以通过按钮的text属性添加文本。

.button-container{
    width: 100px;
    height: 100px;
    overflow: hidden;
    position:relative;
    margin: 5px;
}
.button {
    width: 148px;
    height: 200px;
    transform: rotateZ(45deg);
    overflow: hidden;
    position: absolute;
    top: -68px;
    left: -43px;
}

.button::before{
    content: attr(text);
    background: #6d1a3e;
    display: block;
    width: 100px;
    height: 100px;
    transform: rotateZ(-45deg);
    position: absolute;
    top: 50px;
    left: 50px;
    border: 5px solid #a5285e;
    cursor: pointer;
    box-sizing: border-box;
    text-align: center;
    vertical-align: middle;
    line-height: 69px;
    font-size: 2.5em;
    color: white;
}
.button::after{
    content: '';
    display: block;
    position: absolute;
    border-bottom: 7px solid #a5285e;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    height: 0;
    width: 41px;
    transform: rotateZ(90deg);
    top: 99px;
    left: 120px;
    cursor: pointer;
}


.other.button::before{
    border-left: none;
    border-top: none;
    line-height: 80px;
    font-size: 3em;
}
<div class="button-container">
  <div class="button" text="PDF"></div>
</div>

<div class="button-container">
  <div class="button other" text="&#9776;"></div>
</div>