I have a DIV that has a width of 512px. Then inside that DIV is another DIV. I set the width of THAT DIV to 100%. However, it goes over which is not what I wanted.
I am trying to make it so it stays within the div. As in 5px padding on all sides.
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.
This problem is happening because
paddingandborderare not part ofwidth: 100%.Assuming you do want to absolutely position
#exp_wrap, use this: http://jsfiddle.net/thirtydot/USvTC/1/I removed
width: 100%on.bar_wrap/#exp_wrap, and addedright:5px;on#exp_wrap.A block element such as a
divdefaults towidth: auto, and takes the full available horizontal space. This is similar to howwidth: 100%works, except thatpaddingandborderare counted insidewidth: auto.If
#exp_wrapdoes not need to be absolutely positioned, use this: http://jsfiddle.net/thirtydot/USvTC/2/I removed
width: 100%on.bar_wrap/#exp_wrapagain, and replacedposition:absolute; top:5px; left:5px;withmargin: 5px;. I also addedoverflow: hiddento.containerto avoid collapsing margins.