问题
Currently I am designing a website using CSS and HTML etc. But I have faced a problem there : my child div goes outside the parent div when I add floating to the child. The site resides here my web design
回答1:
Be more specific. Where is the problem on the website?
Try to add this to css, so parent will know about the size of the child element:
#parent{
overflow:hidden;
}
回答2:
You need to clear after your float.
Try adding this css:
CSS
.container:after {
content: "";
display: table;
clear: both;
}
回答3:
Test the follwing CSS
.parentDiv {
float: left,
width: 200px,
height: 30px
}
.childDiv{
float: left,
width: 100px,
}
The child division should be included in the parent one, you can use border on both element to make sure.
来源:https://stackoverflow.com/questions/13777013/child-div-goes-outside-parent-div