how can you make an element with width 100% and padding fit inside another element without changing the width of the parent?
var inp = $('<input type="text" style="padding:4px; width:100%" />')
.appendTo('<div style="width:200px"></div>');
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t use
width: 100%andpadding: 4pxtogether in this case. The element will always be 8px wider than its parent. You have to go with pixel values for your input element. In your case it would bewidth: 192px.The box model always (except some older IE versions) adds the padding (and border) to the elements width. So if the width is 100% each pixel of horizontal padding will make the element wider than its parent.
You could fake your input style this way by achieving the 100% width with padding.