- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I’m pretty new to css layout so maybe I’m doing this all wrong. When I need to float something I seem to need to do a clear:both afterwards to keep from screwing up whatever follows. I’ve been doing it like this:
That really feels like a hack. Is there a better way?
Thanks for the response. I read the article you linked and the ones that one linked plus some others. I guess the empty div approach is pretty standard and it looks to be more straight forward than the alternatives. It just felt wrong so I wanted to make sure it was a good approach before I began using it heavily. Thanks again.
That really feels like a hack. Is there a better way?
You don’t have a width to your floats. Therefore it will float left and set a width to the size of your content within it. The divs with floats positioned after then will float to the left and not clear because of the lack of a width.
That was just a quick example but often I do leave off width. I haven’t run into an issue with it yet but I’m sure it would have driven me crazy when I did. Thanks for the heads up!