如何在按钮上添加斜条

时间:2018-11-02 10:33:08

标签: css html5

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

#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>

但我的目标是:

enter image description here

2 个答案:

答案 0 :(得分:1)

只需将<FrameLayout android:id="@+id/savedContentContainer" android:layout_width="0dp" android:layout_height="0dp" android:background="@android:color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/bottom_handle" /> 添加到父容器中,因为它将隐藏您不需要的部分。

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;
}

答案 1 :(得分:1)

您实际上根本不需要“ bar”元素。

这可以通过成角度的背景渐变来实现

#mybutton {
  background: linear-gradient(124deg, #08c2f3 70%, white 70%, white 75%, #08c2f3 75%);
  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
}
<div id="mybutton">
  <span>OK</span>
</div>