首页 > 解决方案 > 如何在按钮上添加斜杠

问题描述

所以这就是我到目前为止所做的:

#mybutton {
    background-color: #08c2f3;
    width: 200px;
    height: 35px;
    padding: 6px;
    color: white;
    font-size: 30px;
    font-family: sans-serif;
    text-align :center;
    border: 1px solid white;
}

body {
    background-color: #1599e1
}

#myBar {
    width: 100%;
    height: 9px;
    background: white;
    transform: rotateZ(-54deg);
    position: relative;
    left: 42px;
}
<div id="mybutton">
  <span>OK</span>
  <div id="myBar"></div>
</div>

但我的目标是:

在此处输入图像描述

标签: csshtml

解决方案


只需添加overflow: hidden到父容器,因为它会隐藏你不需要的部分窥视。

#mybutton {
  background-color: #08c2f3;
  width: 200px;
  height: 35px;
  padding: 6px;
  color: white;
  font-size: 30px;
  font-family: sans-serif;
  text-align: center;
  border: 1px solid white;
  overflow: hidden;
}

body {
  background-color: #1599e1
}

#myBar {
  width: 100%;
  height: 9px;
  background: white;
  transform: rotateZ(-54deg);
  position: relative;
  left: 42px;
}
<div id="mybutton">
  <span>OK</span>
  <div id="myBar"></div>
</div>


推荐阅读