Div + CSS classic ?? Three-column layout (left and right fixed center adaptive)

Source: Internet
Author: User

 

From http://www.zendstudio.net/post/52/

 

Some people have been asking: "I want to use Div + CSS to implement three-column layout, and I need to fix the left and right width and adapt to the middle. What should I do ?"
I usually reply like this: "in the middle, set margin-left to set the leftdiv width, set margin-right to set the rightdiv width, then the leftdiv float left, And the rightdiv right to float !", But some people say no. I had to prove the correctness of my truth with practice.
OK! Below is my complete testCode.

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <Html Xmlns=Http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta HTTP-equiv="Content-Type" Content="Text/html; charset = gb2312" />
  5. <Title>Untitled document</Title>
  6. <Style Type="Text/CSS">
  7. <! --
  8. *{
  9. Margin: 0;
  10. Padding: 0;
  11. }
  12. . Box {
  13. Width: 100%;
  14. Font-size: 12px;
  15. }
  16. . Leftdiv {
  17. Float: left;
  18. Width: 200px;
  19. Height: 600px;
  20. Background: # f00;
  21. }
  22. . Middlediv {
  23. Background: #0f0;
  24. Height: 600px;
  25. Margin: 0 200px;
  26. }
  27. . Rightdiv {
  28. Float: right;
  29. Width: 200px;
  30. Height: 600px;
  31. Background: # 00f;
  32. }
  33. . Clearfix {
  34. Clear: both;
  35. Font-size: 0;
  36. Height: 0;
  37. }
  38. -->
  39. </Style>
  40. </Head>
  41. <Body>
  42. <Div Class="Box">
  43. <Div Class="Leftdiv">The content of Class "leftdiv" is displayed here.</Div>
  44. <Div Class="Rightdiv">The content of Class "rightdiv" is displayed here.</Div>
  45. <Div Class="Middlediv">The content of Class "box" is displayed here.</Div>
  46. <Div Class="Clearfix">The content of Class "Clearfix" is displayed here.</Div>
  47. </Div>
  48. </Body>
  49. </Html>

Pay attention to the sequence of the three Divs! The IE 3px bug was not fixed, but the performance was hardly affected. The above code passes the test in IE 6 and ff.
From this conclusion, the layout of the two columns is to remove the right div, and then remove the margin-right in the middle.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.