3 replies [Last post]
mickycss02
Offline
Regular
Last seen: 8 years 22 weeks ago
Joined: 2006-06-06
Posts: 49
Points: 14

Whats the best way to have 2 divs side by side.

I'm guessing I could just float them left and right, my question really is do I need to set a specific width for these or can I just put them both to 50%?

thanks.

CupidsToejam
CupidsToejam's picture
Offline
Guru
Florida
Last seen: 4 years 48 weeks ago
Florida
Timezone: GMT-4
Joined: 2008-08-15
Posts: 2637
Points: 1556

use floats. anything that is

use floats. anything that is floated needs a width. width: 50%; is fine. You should really have more of an idea of what you need before getting into css. You need to establish the project requirements. good planning will save time and frustration.

bgbs
Offline
Enthusiast
Last seen: 7 years 47 weeks ago
Timezone: GMT-6
Joined: 2007-08-29
Posts: 102
Points: 52

you can float left or right,

you can float left or right, but you can also add display inline if you are floating both elements to the left for example. But you have to figure out your layout first to determine what you need.

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 5 years 43 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

If the elements contain

If the elements contain other block level elements, display: inline won't be enough; you need floats. Floats also don't need to have a width as they'll automatically shrinkwrap to the width of their contents; sometimes this is what you want, other times you'll want to set the width yourself.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference