How to prevent single-sided border from wrapping around border radius?

非 Y 不嫁゛ 提交于 2020-01-05 04:13:25

问题


I'm applying a 2px bottom border to a text field with a 4px corner radius on the container. Since the radius is larger than the border, it causes the border to curl around the edge. I want the border to stay flat along the bottom edge.

[DON'T want this: border wrapping border radius] https://imgur.com/JEfIkDE

[DO want this: bottom border remains straight] https://imgur.com/xkuQGME

I haven't found a way to fix this within the CSS. Will I have to place another div inside the container to make this work? Basically a 2px high box at the bottom of the container? If so, I would appreciate any help on how that would be structured.

.textfield {
    border-bottom: 2px solid #1A1446;
    border-radius: 4px;
 }

回答1:


Use a gradient at the bottom:

.box {
  width:200px;
  height:100px;
  border-bottom:5px solid transparent; /*keep it transparent*/
  background:
    linear-gradient(#1A1446,#1A1446) bottom/100% 5px border-box no-repeat,
    yellow;
  border-radius: 10px;
}
<div class="box"></div>

If you simply want the visual you can omit the border

.box {
  width:200px;
  height:100px;
  background:
    linear-gradient(#1A1446,#1A1446) bottom/100% 5px no-repeat,
    yellow;
  border-radius: 10px;
}
<div class="box"></div>


来源:https://stackoverflow.com/questions/57153309/how-to-prevent-single-sided-border-from-wrapping-around-border-radius

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!