简体   繁体   English

背景色和边框半径之间的空白区域

[英]Empty space between background-color and border-radius

I saw some white space between green background-color and border-radius (especially when I zoom-in). 我看到绿色背景颜色和边框半径之间有一些空白(尤其是放大时)。

Is there any fix? 有没有解决办法?

https://codepen.io/anon/pen/oPjgJZ https://codepen.io/anon/pen/oPjgJZ

 .container{ width: 250px; height: 300px; background-color: antiquewhite; border: solid 2px green; border-radius: 40px; overflow: hidden; } .header{ height: 15%; background-color: green; display: flex; justify-content: center; align-items: center; } 
 <div class='container'> <div class='header'>HeaderText</div> </div> 

Try this: 尝试这个:

  1. Remove overflow:hidden from .container 清除overflow:hidden.container
  2. Give border-radius:34px 34px 0 0; 给定border-radius:34px 34px 0 0; to .header .header

 .container { width: 250px; height: 300px; background-color: antiquewhite; border: solid 2px green; border-radius: 40px; } .header { height: 15%; background-color: green; display: flex; justify-content: center; align-items: center; border-radius: 34px 34px 0 0; } 
 <div class='container'> <div class='header'>HeaderText</div> </div> 

I don't know what the reason is, but I just change background-color color-block to linear-gradient in parent's css to make sure the background's color on 15% height parent has same color with the header. 我不知道是什么原因,但是我只是将background-color色块更改为父级css中的linear-gradient ,以确保高度15%的父级上的背景色与标头具有相同的颜色。 So there is no any white-space anymore. 因此,不再有任何空格。

 .container{ width: 250px; height: 300px; border: solid 2px green; border-radius: 40px; overflow: hidden; background: linear-gradient(to bottom, green, 15%, antiquewhite 15%); } .header{ height: 15%; background-color: green; display: flex; justify-content: center; align-items: center; } 
 <div class='container'> <div class='header'>HeaderText</div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM