http://jsbin.com/nuzazefuwi/1/edit?html,css,output
In the link above the textbox should have only 10px instead it has a width of 152px
.
This is the code:
.input { width: 100%; box-sizing: border-box; } .cont { padding: 2px; } .main { position: absolute; border: 1px solid black; min-width: 15px; }
<div class='main'> <div class='cont'> <input type="text" class='input' /> </div> </div> <br/> <br/> <br/> the textbox should have 10px
It looks like the input starts to get the correct width only after .main
min-width
is greater than 156px.
The min-width property in CSS is used to set the minimum width of a specified element. The min-width property always overrides the width property whether followed before or after width in your declaration. Authors may use any of the length values as long as they are a positive value.
Change the maximum width. max-width overrides width , but min-width overrides max-width .
And min-width specify lower bound for width. So the width of the element will vary from min-width to ... (it will depend on other style). So if you specify min-width and max-width , you will set up a lower and upper bound and if both are equal it will be the same as simply specifing a width .
Definition and UsageThe width attribute specifies the width of the <input> element. Note: The width attribute is used only with <input type="image"> . Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded.
There is size="20"
set on <input>
type text
, search
, tel
, url
, email
, and password
... by default, which is approximately of 100px
width, although it can vary in a different browser and operating system.
On the parent, you have min-width:15px;
set, that does not take any effects, because the value is much smaller than 100px
. If you change it to width:15px;
or max-width:15px;
you will then see the differences.
Alternatively you can give the size
a very small value such as size="1"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With