Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't the <input> element respect min-width?

Tags:

html

css

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.

like image 666
Omu Avatar asked Apr 06 '15 11:04

Omu


People also ask

Does width override min-width?

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.

Does Min-width override max-width?

Change the maximum width. max-width overrides width , but min-width overrides max-width .

Can we set min-width and max-width for an element at the same time?

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 .

How do you change the input field 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.


1 Answers

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".

like image 196
Stickers Avatar answered Sep 22 '22 12:09

Stickers