简体   繁体   English

边框半径不带父高度的子容器

[英]Child container with border-radius not taking parent height

I have a fiddle which tries to place a absolute positioned circle at the center of the parent. 我有一个小提琴 ,试图在父母的中心放置一个绝对定位的圆圈。 Somehow I have to give an extra pixel of padding in the child to cover the height of the parent container. 不知何故,我必须在子节点中添加一个额外的填充像素来覆盖父容器的高度。

Is there a way to avoid this extra pixel. 有没有办法避免这个额外的像素。

padding: ($padding + 1); /*need to avoid this addition of 1 pixel*/

Any other suggestions are most welcome! 欢迎任何其他建议!

The problem is caused by the font-size you define in your .buttonContainer class which will add a bit of extra padding around the contents. 问题是由你在.buttonContainer类中定义的font-size引起的,它会在内容周围添加一些额外的填充。 If you set a line-height of "24px", you can remove the additional pixel (in fact you would have needed 2px to have the same height) as can be seen in this fiddle . 如果您将line-height设置为“24px”,则可以删除其他像素(实际上您需要2px才能具有相同的高度),这可以在此小提琴中看到。

Here's your changed code: 这是你改变的代码:

.buttonContainer {
  /* ... */
  line-height: 24px;
  /* ... */
}

.buttonCounter {
  /* ... */
  padding: ($padding);
  /* ... */
}

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

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