Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Caroline Heim
6,959 PointsWhy does the inner div go outside its outer div?
Hi friends!
I am asking for your help:
So basically I have two divs within an outer div.
I put the inner divs to have a width of 100%. Weirdly enough, they go outside the outer div towards the right.
How can this happen? I want the inner divs to align to the width of the outer div using the property of width: 100%.
Also I dont want to use overflow: hidden, because of border-radius properties of the inner divs.
I tried to do something smart with the clear:both property in css.... and a lot more I tried to do to fix it but it doesnt work.
I dont get it, how can something like this ever happen?
If there is anyone who could help me..... ...I would be so grateful =)
Liine
9 Answers
Mike Baxter
4,442 PointsHmm... It's hard to say without playing around with that code. What if you comment out the contact form and just leave the "Betreff" and "Nachricht"?

Ben Polgardy
8,132 PointsHi!
Did you try position: relative on the inner div?

banned banned
Courses Plus Student 11,243 PointsMake sure your outer div, body and HTML wrappers also have a width and a height of 100%

Caroline Heim
6,959 PointsPosition: relative didnt work. Naww. But thanks!
The outer div has a width and height of 100%, the content div in which all of this is placed, on the other hand, has a width of some 770px. Maybe it has to do with that?

Caroline Heim
6,959 PointsThank you both for quick answers, though! =D
Mike Baxter
4,442 PointsI'm just trying to picture what you're doing. How close is this CodePen to what you're doing?
(Note, I had to set the inner-div width to 90% to account for the 5% padding on the left and right.)
Background colors are merely so you can see the containers. Of course, you can set body margins to whatever, and the outer-div width to whatever, I'm just trying to visualize what you're asking.

Caroline Heim
6,959 PointsYes, this is spot on what I have!
Now the thing is, that these divs come from the contactform 7 plugin.
The html looks like this:
<div id="kontaktformular">
<table class="kontakt_table"><tr><td> [text* name id:kontakt_name class:kontaktformular placeholder "Ihr Name"]</td><td> [email* email id:kontakt_email class:kontaktformular placeholder "Ihre E-mail"]</td> </tr> </table> <div class="kontakt_table"><div> [text* betreff id:kontakt_betreff class:kontaktformular placeholder "Betreff"]</div><div> [textarea* nachricht id:kontakt_nachricht class:kontaktformular placeholder "Ihre Nachricht"]</div></div> </div>
and the css:
/* Kontaktformular */
.kontaktformular { padding: 10px; margin-bottom: 16px; border: none; border-bottom: 2px solid #4D4D4D; border-radius: 3px 3px 0 0; }
#kontakt_name,
#kontakt_email {
float: left;
width: 92%;
}
#kontakt_email{
float: right;
}
.kontakt_table {
width: 100%;
height: 100%;
}
#kontakt_betreff,
#kontakt_nachricht {
width: 100%;
}
The table is there to put the first two fields in a row.... unsure if this is the best way to do this, but it works.
What doesn't work, are the two after that ("Betreff" and "Nachricht"). They jump outside the outer divs!
It works for you in the CodePen, so could this have do do anything with the plugin it self? But why do then upper two fields work, and not the lower fields? (I tried putting the last two fields into a table as well, but that doesnt help...)
hmmmm...

Caroline Heim
6,959 Pointsoh thats weird, the html code disappeard..
here it comes again (if this works ^^):
<xmp>
<div id="kontaktformular">
<table class="kontakt_table"><tr><td> [text* name id:kontakt_name class:kontaktformular placeholder "Ihr Name"]</td><td> [email* email id:kontakt_email class:kontaktformular placeholder "Ihre E-mail"]</td> </tr> </table> <div class="kontakt_table"><div> [text* betreff id:kontakt_betreff class:kontaktformular placeholder "Betreff"]</div><div> [textarea* nachricht id:kontakt_nachricht class:kontaktformular placeholder "Ihre Nachricht"]</div></div> </div>
</xmp>
nope, doesnt work... hmm

Caroline Heim
6,959 PointsWhat a great idea! Thank you, Ill try that =)