如何为椭圆的左侧应用CSS边框颜色?

时间:2019-04-23 21:16:57

标签: css border

我正在尝试仅对椭圆的左侧应用白色边框,并使另一侧保持透明,但是,边框并未应用到左侧的整个部分。显示预期的输出?

#ellipsis {
  background-color: #3ebede;
  height: 25px;
  color: #000;
  position: relative;
  padding: 4px 15px 4px 30px;
  width: 200px;
  border-radius: 20px;
  margin: -4px -25px -4px -4px;
  text-align: left;
  display: inline-block;
  border: solid;
  border-color: transparent transparent transparent white
}
<body>
  <button id="ellipsis"></button>
  <button id="ellipsis"></button>
  <button id="ellipsis"></button>

</body>

链接到我的代码: https://jsbin.com/bebekirano/edit?html,output

Expected output

1 个答案:

答案 0 :(得分:7)

改为考虑box-shadow

.ellipsis {
  background-color: #3ebede;
  height: 25px;
  color: #000;
  position: relative;
  padding: 4px 15px 4px 30px;
  width: 200px;
  border-radius: 20px;
  margin: -4px -25px -4px -4px;
  text-align: left;
  display: inline-block;
  box-shadow:-2px 0 0 2px #fff;
  border:none;
}
<body>
  <button class="ellipsis"></button>
  <button class="ellipsis"></button>
  <button class="ellipsis"></button>

</body>

如果您想要透明度,可以使用radial-gradient的一个技巧:

.ellipsis {
  background-color: #3ebede;
  height: 25px;
  color: #000;
  position: relative;
  padding: 4px 15px 4px 30px;
  width: 200px;
  border-radius: 20px;
  margin: -4px -25px -4px -4px;
  text-align: left;
  display: inline-block;
  border:none;
}
.ellipsis:not(:last-child) {
  background:radial-gradient(4px 3px at right,transparent 30px,#3ebede 31px); 
}

body {
  background:#ddd;
}
<div>
  <button class="ellipsis"></button>
  <button class="ellipsis"></button>
  <button class="ellipsis"></button>

</div>