如何在单选按钮中设置边框半径?

时间:2020-09-30 12:47:43

标签: html css

如何在单选按钮中设置border-radius? 如何将border-radius应用于box类?

.box {
  width: 300px;
  height: 60px;
  background: red;
  display: flex;
  align-items: center;
  border-radius: 50px;
}

.item {
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  color: red;
  justify-content: center;
  align-items: center;
}

.item_active {
  background: gray;
}
<div class="box">
  <div class="item_active item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
</div>

我将其设置为50px,但是由于某种原因它不起作用。

1 个答案:

答案 0 :(得分:1)

您需要在.box类中添加隐藏的溢出内容,以使边框半径可以削减底层内容。

.box {
  width: 300px;
  height: 60px;
  background: red;
  display: flex;
  align-items: center;
  border-radius: 50px;
  overflow: hidden;
}
.item {
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  color: red;
  justify-content: center;
  align-items: center;
}
.item_active {
  background: gray;
}
<div class="box">
  <div class="item_active item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
</div>