Say you have a div, give it a definite width and put elements in it, in my case an img and another div.
div
width
img
The idea
W3Schools recommendation:
put overflow: auto on parent element and it will "color" whole background including elements margins. Also floating elements will stay inside of border.
overflow: auto
http://www.w3schools.com/css/tryit.asp?filename=trycss_layout_clearfix