[英]How can I limit the resize scale of a div so it cant get bigger than the parent div
So I got a resizable Div which lays in the parent Div.所以我得到了一个可调整大小的 Div,它位于父 Div 中。 The Problem is, I can resize the childDiv much larger than the parentDiv.
问题是,我可以调整 childDiv 的大小比 parentDiv 大得多。 How can i limit the resizing?
如何限制调整大小?
.borderbox { float: left; height: 500px; width: 50%; background: white; border: 1px solid black; }.movebox { height: 100px; width: 200px; position: absolute; overflow: auto; resize: both; display:flex; background-color: orange; }
<div class="borderbox"> <div class="movebox"> </div> </div>
You can set the parent to position: relative;
您可以将父级设置为
position: relative;
and then apply a max-width
and max-height
of 100%
to your child element.然后将
100%
的max-width
和max-height
应用于您的子元素。
.borderbox { float: left; height: 500px; width: 50%; background: white; border: 1px solid black; position: relative; }.movebox { height: 100px; width: 200px; max-width: 100%; max-height: 100%; position: absolute; overflow: auto; resize: both; display:flex; background-color: orange; }
<div class="borderbox"> <div class="movebox"> </div> </div>
You can remove position: absolute;
您可以删除
position: absolute;
in class movebox
在
movebox
Demo:演示:
.borderbox { float: left; height: 500px; width: 50%; background: white; border: 1px solid black; }.movebox { height: 100px; width: 200px; overflow: auto; resize: both; display:flex; background-color: orange; max-width: 100% }
<div class="borderbox"> <div class="movebox"> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.