Effect:
Main: I am the DIV with the package outside.
Col1 I'm the first column col2 I'm the second column clear-float; I used to clear float (clear float)
The following is a description:
CSS code:. Main {width: 800px;/* total width */Background: red ;}. main. col1 {float: Left;/* This is the key place for col1 to float to the left, so that other elements (other elements: div, image, text) */width: 300px; Height: 300px; Background: # Eee; Border: 1px solid # CCC ;}. main. col2 {float: Left;/* This is the key place for col2 to move to the left, followed by col1 */margin-left: 5px; /* set the interval between col2 and col1 */width: 490px; Height: 300px;/* give a dimension as needed */Background: # DDD; Border: 1px solid # CCC ;}. clear-float {clear: both}/* Clear C Float of ol1 and col2; otherwise, the height of the main will fail and there will be no float elements in it. */HTML structure:<Div class = "Main"> main <Div class = "col-1"> col1 </div> <Div class = "col-2"> col2 </div> <div class = "Clear-float"> clear-float </div>
Run codeNo coloring mode copy printing?
- <Style type = "text/CSS">
- Body {font-size: 12px ;}
- . Main {width: 800px;/* total width */
- Background: yellow;
- }
- . Main. col-1 {
- Float: Left;/* This is the key place for col1 to float to the left, so that other elements (other elements: div, image, text )*/
- Width: 300px; Height: 300px;
- Background: # Eee; Border: 1px solid # CCC;
- }
- . Main. col-2 {
- Float: Left;/* This is the key place for col2 to move to the left, followed by col1 */
- Margin-left: 5px;/* interval between col2 and col1 */
- Width: 490px; Height: 300px;/* give a random size */
- Background: # DDD;
- Border: 1px solid # CCC;
- }
- . Clear-float {clear: both}/* clear the float of col1 and col2. Otherwise, the height of the main will fail and there will be no float elements in it. */
- </Style>
- <Div class = "Main"> main is the DIV of the package.
- <Div class = "col-1"> col1 is the first column </div>
- <Div class = "col-2"> col2 is the second column </div>
- <Div class = "Clear-float"> clear-float; I used to clear float </div>
- </Div>