Making Guide website: CSS page layout realization
Page Layout
CSS layout used to be easy. If you have already used by the layout of form, initially will feel more difficult. In fact, it is not difficult, just different motives, and in practice more meaningful.
You can put all parts of the page as a separate section to look at, no matter which one you choose. You can use absolute or relative He replaced block this block.
Positioning
Positioning position attribute is used to define an element of the absolute (absolute), relative (relative), static (static) or fixed (fixed).
Static element value is the default value, it will generate in accordance with the general order, as they appear in the HTML general.
Relative like static, but can be top, right, bottom and left property to offset its original location.
HTML elements from the absolute flow separated from the ordinary, and it belongs to a fully its position World. In this slightly crazy world, and this is an element that can be placed anywhere, as long as the set top, right, bottom and left values.
Fixed acts like absolute, but reference in the browser window of the page and placing absolute element, so, theoretically, when the rolling pages, fixed elements remain entirely in the browser, as in the District. Why do I say that theory? Is not for any other, in Mozilla and Opera work very well, but not IE.
Using absolute positioning layout
The following is quoted fragment:
<div Id="navigation">
<ul>
<li> <a Href="this.html"> This </ a> </ li>
<li> <a Href="that.html"> That </ a> </ li>
<li> <a Href="theOther.html"> The Other </ a> </ li>
</ Ul>
</ Div>
<div Id="content">
<h1> Ra ra banjo banjo </ h1>
<p> Welcome to the Ra ra banjo banjo page. Ra ra banjo banjo. Ra ra banjo banjo. Ra ra banjo banjo. Ra ra banjo banjo. </ P>
<p> (Ra ra banjo banjo) </ p>
</ Div>
You can use absolute positioning to create a layout of the traditional two, as long as the HTML used similar rules as in the following:
And the application of CSS as follows:
# Navigation (position: absolute; top: 0; left: 0; width: 10em;) # content (margin-left: 10em;)
You will see that the length of the navigation of the 10 em is set on the left. Because it is absolutely positioning navigation on the pages of other parts of the flows will not have any effects, therefore, need to do is just to the left border of regional content set to the width of the navigation can be the same width.
It is too easy! But you are not covered by the two methods restrictions. With smart positioning, you can layout you if you needed more blocks. For example, you need to increase the third out, you can increase the HTML "navigation2" CSS block and application are as follows:
# Navigation (position: absolute; top: 0; left: 0; width: 10em;) (# navigation2 position: absolute; top: 0; right: 0; width: 10em;) (# content margin: 0 10em; / * setting top and bottom margin to 0 and right and left margin to 10em * /)
The only absolute positioning elements of side effects, because they live in their own world, they have no way accurately determine where the end. If you use the above example in a little more navigation and content areas, there is no problem, but, in particular the use of the width and length of the relative values, you are often placed below abandon any hope that things such as footnotes. If you really do, instead of absolute positioning them as they float.
Floating
Will move a floating element to the same line of the left or the right, and the content will also be floating around.
Floating in the positioning of a frequently used pages of small elements (in the original default CSS Site in the primary guide to HTML and CSS primary guide, "Next" link is floating to the right. Refer to the same pseudo-elements: first - letter example), but also can be used in larger pieces, such as navigation out.
With the following HTML example, you can then use the CSS:
# Navigation (float: left; width: 10em;)
# Navigation2 (float: right; width: 10em;)
# Content (margin: 0 10em;)
If you do not want a floating objects around the elements, you can use clear (removal) attributes. Clear: left to remove the left element clear: right to remove the right elements, and clear: both will be cleared away left and right. So, for example, you need a page footnote, you can use id "footer" HTML increase in a block, then use the following CSS:
# Footer (clear: both;)
Ah, you have to get. A footnote will appear in the list below of all, regardless of how long any one out.
Attention
We have already introduced the general status and floating pages highlighted the "big" pieces, but please keep in mind that these methods can be used in any of these elements within the block. Integrated positioning, the floating, borders, and the white-frame, you can reproduction of any layout, in the layout, there is no CSS completed forms can be completed things.
Use of form layout is the sole reason for you to adapt to the old browser. This is actually demonstrate its advanced CSS place ─ ─ in file size, high ease-of-use is based on the pages of forms only a small part of pages.
Tags: css layout, div css Guide, div css layout, div layout, layout examples, w3c website w3c statement w3c css






Leave a Reply