, Table, form, divAnd body. Inline elements, such as form elements, Hyperlink, image,
... The notable feature of block-level element-free is that each block-level element is displayed from a new line, and the subsequent element-free must be displayed in another line.From the example, we can see that a block-level element occupies a row by default, which is equivalent to inserting a line break before and after it. The Inline element span does not affect the display effect, as is the case; em only changes the font into italics and does not occupy a single row. This is a block-level element and an inline element. With these elements, our web page becomes rich and colorful.
If no CSS function is available, the block elements are arranged in the order of each row. With CSS, we can change the default layout of HTML and place block elements in the desired position. Instead of just starting another line. That is to say, you can use the display: inline function of CSS to change block-level elements to inline elements, or use the display: Block Function to change inline elements to block elements.
5. Float attributesBack to our example, we understand block-level elements and inline elements, and it is much easier to understand floating. Float is a key point and I hope everyone can understand it. In the above example, float is used to float the element to the left. In CSS, any element can float. A floating element will generate a block-level box, regardless of its own elements. It must specify a width, otherwise it will be as narrow as possible; in addition, when the available floating space is smaller than the floating element, it will run to the next row until it has enough space to put it down.
I think everyone has used the word layout, which has a text-and-text mixed layout function, such:
This function is very similar to the float in CSS. We will use CSS to implement this function:
Standard path [www.aa25.cn] provides Div + CSS tutorials, div + CSS video tutorials, Web2.0 standards, div + CSS layout tutorials, webpage layout instances, and CSS layout instances, div + CSS template, div + CSS instance parsing, website reconstruction, webpage code, crystal icon, and magic lamp advertisement image. this tutorial is suitable for beginners to learn in a step-by-step manner!
After the above Code is created, the following result is displayed in the browser preview:
The following uses CSS to float the side and check the effect.
Body {font-size: 18px; line-Height: 200% ;}
# Side {float: Left ;}
Let's see if it is similar to the word, but the text here is very close to the text on the right side of the image. What should I do? As we have already said, when an element floats, You need to specify a width, otherwise it will be as narrow as possible. Set the side width to be greater than the image width, and there should be gaps between them. The width of the image is 192px, and the side is set to 202px. There will be a 10px gap in the middle.
Body {font-size: 18px; line-Height: 200% ;}
# Side {float: Left; width: 202px ;}
Careful friends have found that the # Main DIV in the above example also defines the margin-left: 120px, which is not defined here, but the extra text is uploaded to the image (# side) at the bottom of the page, is it true that after margin-left: is set, it will not run to the # side body? If you can think of this, you are indeed too smart. The fact is, add the following row in the CSS style sheet.
# Main {margin-left: 202px ;}
This is how to apply the floating principle to implement the two-column layout. What about three columns?
6. Adaptive width of three columnsAdaptive width of three columns. Generally, the left and right columns are fixed. The middle columns are adaptive according to the browser width. Next, modify the adaptive width based on the two columns.
The content of ID "side" is displayed here
The content of ID "side1" is displayed here
The content of ID "Main" is displayed here.
Add the following CSS style:
# Side1 {Background: #99ff99; Height: 300px; width: 120px; float: Right ;}
Remove the width: 70% of the original # main style, and set 120px of the left and right margins to give the width of the left and right columns.
# Main {Background: #99 FFFF; Height: 300px; margin: 0 120px ;}
The preview effect is as follows:
Maybe the preview effect is different from mine. Don't worry. There is another setting. The default body has an outer margin, so we have to set the body's outer margin to 0 here; click the new button on the CSS panel, and then select: Label (redefinition label appearance) in the new panel. Then select the body and set the boundary of the body to 0.
The content of ID "side" is displayed here the content of ID "side1" is displayed here the content of ID "Main" is displayedTip: you can modify some code before running the fixed width of the seven or three columns.
You can add a parent Div based on the three columns of fixed width and set the DIV width. Add a parent container whose ID is content as follows.
Select the three divs in the source code, and click the "insert Div tag" button on the toolbar. The displayed window will display a line break next to the selected content by default, enter the ID as content and define a width for this Div.
The fixed width of the three columns has come out. to center the fixed width of the three columns, you only need to set # Content {margin: 0 auto ;}.
The content of ID "side" is displayed here the content of ID "side1" is displayed here the content of ID "Main" is displayedTip: you can modify some of the code before running the Three-pixel bug of IE6.
The 3 pixel bug is a famous bug in IE6. When floating elements are adjacent to non-floating elements, this 3 pixel bug will appear. The CSS code is as follows:
Body {margin: 0 ;}
# Side {float: Left; Background: #99ff99; Height: 300px; width: 120px ;}
# Main {Background: #99 FFFF; Height: 300px ;}
The HTML code is as follows:
The content of ID "side" is displayed here
The content of ID "Main" is displayed here.
Let's take a look at the display effects in IE6 and IE7:
Obviously, IE6 will add a 3px gap between the two divs. To solve this problem, add _ margin-Right:-3px on # side. Remember, add an underline to the front, so that this style takes effect for IE6. IE7 and FF are displayed normally.
Body {margin: 0 ;}
# Side {float: Left; Background: #99ff99; Height: 300px; width: 120px; _ margin-Right:-3px ;}
# Main {Background: #99 FFFF; Height: 300px ;}
Check whether the problem has been solved. However, it cannot pass W3C verification. When the two columns are fixed in width, it is best to set # Main to a fixed width and float to the right, so as to avoid the 3 pixel bug of IE6.