简体   繁体   English

当父母的宽度没有超过其最大宽度值时,如何让孩子的宽度不超过父母的宽度?

[英]How to get the child width to not exceed the parent's width when parents width did not exceed its max-width value?

The parent div's width did not exceed the value set in its max-width property.父 div 的宽度没有超过其max-width属性中设置的值。 How to get child to inherit the actual width of the parent and not cause the parent to increase its width?如何让子继承父的实际宽度而不导致父增加宽度?

I'm sorry but I didn't really understand the question, but I think what you are searching for is this:对不起,我不太明白这个问题,但我想你正在寻找的是这个:

 .parent-el { max-width: 100px; width: 50px; border: 3px solid black; }.child-el { height: 100px; width: 100%; background-color: red; }
 <html> <div class="parent-el"> <div class="child-el"></div> </div> </html>

I set the child's width to 100%.我将孩子的宽度设置为 100%。 If you set the child's width to 100%, the child's width becomes 100% of the parent's width.如果将子项的宽度设置为 100%,则子项的宽度将变为父项宽度的 100%。 For example if the parent's width is 50px and you set the child's width to例如,如果父项的宽度为 50px,而您将子项的宽度设置为

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

相关问题 展开div以填充父元素,但不超过最大宽度 - Expand divs to fill parent element but not exceed max width 如何将子 div 宽度设置为等于 max-width 但以父级为中心 - How can I set child div width equal to to max-width but centered of parent 定义最大宽度时,在野生动物园中获取实际的表宽度 - Get real table width in safari when max-width is defined 如何获取li元素的最大宽度 - How to get the max-width in li element 如何在 CSS 中隐藏超出父级宽度的子元素 - How to hide thoes children elements that exceed the paraent's width in CSS 将 DIV 缩小到包装到最大宽度的文本? - Shrink DIV to text that's wrapped to its max-width? 子元素的宽度可以覆盖父元素设置的最大宽度。 我怎样才能防止这种情况发生? - Width of child element is able to override max-width set by parent element. How can I prevent this from happening? 如何获得拆分层的内容容器最大宽度以匹配全宽层的宽度? - How do I get the content container max-width of a split tier to match the width of a full width tier? 当以百分比声明父级宽度时,固定位置的子级是否具有与其父级相同的确切宽度? - Have fixed positioned child obtain the same exact width of its parent, when parent's width is declared in percentages? 使用max-width属性获取img元素的调整大小的宽度和高度 - Get Resized Width and Height of img Element with max-width Property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM