简体   繁体   English

使用圆角时,子div不会填充父div

[英]Child div does not fill the parent div when using rounded corners

Per the title, you can see a demo of the issue here . 按照标题,您可以在此处查看该问题的演示。

Here is the HTML code: 这是HTML代码:

<div id="outer">
    <div id="inner">
    </div>
</div>

Here is the CSS code: 这是CSS代码:

#inner{
  height: 100%;
  width: 100%;
    border-radius: 20px;
    text-shadow: 5px 5px 5px #000000;
    background-color: white;
    opacity: 0;
    -webkit-transition: opacity .5s linear;
    -moz-transition: opacity .5s linear;
    transition: opacity .5s linear;
}

#inner:hover{
    opacity: 1;
}

#outer{
    border: 6px solid #dcc5c5;
    border-radius: 20px;
    text-shadow: 5px 5px 5px #000000;
    position: relative;
    display: inline-block; 
    transition: all 0.5s ease-in-out;
    background-color: red;
  height: 200px;
  width: 200px;
}

I've tried various suggestions here and here with no solution. 我在这里这里都尝试过各种建议,但没有解决方案。

you are using margin-top:20px; 您正在使用margin-top:20px; in this element 在这个元素中

#inner {
    height: 100px;

    background-color: #42749F;
    width: 200px;

    /* -1px here for to compansate for the outer border of the container */
    -moz-border-radius: 0 0 9px 9px;
}

remove margin and it will fill inside parent element 删除边距,它将填充到父元素内部

Working fiddle 工作提琴

The problem in that is that the child takes priority, if the parent div says: 问题在于,如果父div说:

text-font: Sans-Serif

but the child says: 但是孩子说:

text-font: Arial

the elements in the child sector take priority. 儿童部门的要素优先。 In other words, the parent is the "Default". 换句话说,父级是“默认”。 The same happens to "rounded corners" and "margin-top". “圆角”和“边距”也相同。 The "margin-top" takes priority. “ margin-top”优先。

Just make sure that those two are correct. 只要确保这两个是正确的即可。

I guess the border you've set on the inside division is creating problems here. 我想您在内部部门设置的边界在这里造成了问题。 Removing the border makes the child element fully fill the parent. 删除边框会使子元素完全填充父元素。

Is this what you were looking for? 这是您要找的东西吗? You may elaborate more if you want, in comments. 如果需要,您可以在注释中详细说明。

 .box { position: relative; overflow: hidden; border-radius: 20px; transition: all 0.5s ease-in-out; background-color: red; height: 200px; width: 200px; } .scratcher{ height: 100%; width: 100%; background-color: white; opacity: 0; transition: opacity .5s linear; } .scratcher:hover{ opacity: 1; } 
 <div class="box"> <div class="scratcher">Scratcher</div> </div> 

I noticed that if you offset the difference ( 6px ) in border-width of the containing element ( .box_1 / #outer ), with the border-radius of the nested element ( #scratcher / #inner ), you will fill up the corner gaps. 我注意到,如果您将包含元素( .box_1 / #outer )的border-width的差异( 6px )与嵌套元素( #scratcher / #inner )的border-radius #scratcher / #inner ,则将填满角落差距。

Deduct 6px from the border-radius value of the nested element ( #scratcher / #inner ). 扣除6pxborder-radius的嵌套元素(的值#scratcher / #inner )。

 #inner { height: 100%; width: 100%; border-radius: 13px; text-shadow: 5px 5px 5px #000000; background-color: white; opacity: 0; -webkit-transition: opacity .5s linear; -moz-transition: opacity .5s linear; transition: opacity .5s linear; } #inner:hover { opacity: 1; } #outer { border: 6px solid #dcc5c5; border-radius: 20px; text-shadow: 5px 5px 5px #000000; position: relative; display: inline-block; transition: all 0.5s ease-in-out; background-color: red; height: 200px; width: 200px; } 
 <div id="outer"> <div id="inner"> </div> </div> 

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

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