Div带左边和宽度:100%溢出在右边 [英] Div with margin-left and width:100% overflowing on the right side
问题描述
我有2个嵌套div,应该是100%宽。不幸的是,内部div与Textbox溢出,实际上大于外部div。它有一个左边距,溢出大约边缘的大小。
I have 2 nested div's that should be 100% wide. Unfortunately the inner div with the Textbox overflows and is actually larger than the outer div. It has a left margin and overflows by about the size of the margin.
如何解决这个问题?
<div style="width:100%;">
<div style="margin-left:45px; width:100%;">
<asp:TextBox ID="txtTitle" runat="server" Width="100%"></asp:TextBox><br />
</div>
</div>
如果我不做100%,那么文本框不是100%宽。 p>
If I don't do the 100%, then the textbox is not 100% wide.
推荐答案
只需从两个div中删除宽度。
Just remove the width from both divs.
A div
是一个块级元素,将使用所有可用空间(除非您开始浮动或定位它们),因此外部div将自动为100%宽,内部div将使用所有剩余空间
A div
is a block level element and will use all available space (unless you start floating or positioning them) so the outer div will automatically be 100% wide and the inner div will use all remaining space after setting the left margin.
我已经在 textarea //jsfiddle.net/qRJmW/\"> jsfiddle 。
I have added an example with a textarea
on jsfiddle.
这篇关于Div带左边和宽度:100%溢出在右边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!