Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what's the best way of horizontally aligning elements?

Status
Not open for further replies.

soniclnd

Technical User
Jan 6, 2005
51
US
besides tables, what is the best way to horizontally align elements?

float: left; or float: right; seems good but if the scree size decreases then the div's move down and the layout messes up

btw: what does XHTML have agains tables and frames?
 
Horizontally align elements? Well, float usually suits my purposes for left or right-aligning objects, and you can use "margin: auto" (or "margin: 0 auto" or "margin-left: auto; margin-right: auto") to horizontally center elements (though I'm not sure what happens when you combine floats and this kind of margin setting. . .)

What does XHTML have against tables and frames? It's not XHTML, but end-users (because of browsers) actually. Tables are good, but they make a page take a long time to load, especially if you have a lot of images. Regarding frames, I have nothing against them personally, but they are bad for accessibility, such as screen readers. Also, many people use text browsers rather than graphical browsers, so the page looks odd because frames are not implemented in many text browsers.
 
This might be one way to prevent the problem that you describe: enclose the floating divs within a div which has an explicit width. That will force the browser to show a scrollbar when the page width is reduced too much. That should stop the floating images from stacking. There are some disadvantages to this method too, so see if it works for you.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
You could also use the overflow property on the body (or the page container if you have a page container). This also works well, though it can cause some headaches if not used properly (I can't think of any problems right now. . .)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top