CodeSipper - Vancouver BC Website Design and Development

Dave Peatling

Menu

Main Navigation

  • home
  • projects
  • about
  • blog
  • contact

Head Scratching Floats

May 10, 2013.

No Comments

dog_float
I feel I’m moving on in leaps and bounds with CSS recently but there’s one area that I’m having to really get my head around, “floated elements”. When you float an element, like a heading, paragraph, list or div, it becomes a block container. This container can then be shifted left or right of the current line by using the markup “float: left” or “float:right”. Other content can then flow down the right hand side of a float-left box and the left hand side of a float-right box. You always need to set a width for your floated element, if you don’t set a width then you can get some unpredictable outcomes.

It also took me a while to get straight in my mind that, for example, you may have floated a containing element to the right but all of the contents of that element will still have normal document flow within that container. So if you want the contents of the container also to float right then you would also need to apply that syntax to that element as well. Sounds easy, right?

Another problem with floating elements is that the parent element does not recognize its child’s height. This means that the parent will lose its height if it only get its height from the height of its child. When this happened to me for the first time it had me scratching my head for a while. The answer is to apply the mark up “overflow:hidden” to the parent element. The parent element will then recognize the height of its child and all will look great. Got it? I did have to wash, rinse and repeat this one a few times to make it stick.

RECENT POSTS

  • Hello Mudder . . . .
  • How often should you redesign your site?
  • The Benefits of Responsive Design
  • It’s time to plug-in your timeline
  • WordCamp Vancouver? … magnifico!

ARCHIVES

  • January 2014
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013

© 2025 CodeSipper

Back to the Top

Bottom Navigation

  • home
  • projects
  • about
  • blog
  • contact