1) If textbox element (<input type=”text” />
) has its width
property set to inherit
, then textbox doesn’t overflow. But if textbox has width
set to auto
, then it overflows due to browser calculating the width
.
a) Why doesn’t browser take into the account that textbox is inside another element and thus adjusts the width
of a textbox accordingly?
b) Based on what parameters does it decide what the width
of a textbox should be?
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<style type="text/css">
p
{
width:60px;
}
</style>
</head>
<body>
<p>
<input type=”text” />
</p>
</body>
</html>
2) Do all Html elements by default have their width value set to auto?
thanx
You can find various rules for calculating the width for
width:auto
here.Regarding inherit:
So
width:inherit
means it takes the same computed width as the parent element.Regarding
width:auto
on inline elements:So for inline elements in many cases, the "intrinsic" width of the element is used (even if this is wider than the parent element).
Note that there are different rules for block-level and floating elements, but
<input>
is naturally an inline elementwidth:auto
is the default value