Home > Web Front-end > CSS Tutorial > How to use CSS for web page layout

How to use CSS for web page layout

巴扎黑
Release: 2017-03-30 15:20:15
Original
2699 people have browsed it

Day 1: What kind of DOCTYPE to choose

Preface

Hi everyone! This series of articles is written based on Ajie's own process of creating the w3cn.org site. Ajie has never produced a website that truly complies with web standards before. Now I am making reference to foreign materials and recording my thoughts and experiences in the process. I hope it will be helpful to everyone. Okay, let's get started.

The first day

Start making a site that meets standards. The first thing to do is to declare the DOCTYPE that meets your needs.

Look at the original code of the homepage of this site, you can see that the first line is:



Open some sites that meet standards, such as the famous web design software developer Macromedia and the personal design master Zeldman website, you will find the same code. The code for other standards-compliant sites (such as k10k.net) is as follows:



So what do these codes mean? Does it have to be placed?

What is DOCTYPE

We call the above codes a DOCTYPE statement. DOCTYPE is the abbreviation of document type and is used to indicate what version of XHTML or HTML you are using.

The DTD (such as xhtml1-transitional.dtd in the above example) is called the document type definition, which contains the rules of the document. The browser will interpret the identity of your page based on the DTD you define and display it. come out.

To build a standards-compliant web page, the DOCTYPE declaration is an essential and critical component; unless your XHTML determines a correct DOCTYPE, neither your logo nor your CSS will take effect.

XHTML 1.0 provides three DTD declarations to choose from:

Transitional (Transitional): A DTD with very loose requirements, which allows you to continue to use the HTML4.01 identifier (but must comply with xhtml writing method). The complete code is as follows:



Strict: For strict DTD, you cannot use any presentation layer identifiers and attributes, such as
. The complete code is as follows:



Frameset: A DTD specifically designed for frame pages. If your page contains a frame, you need to use this DTD. The complete code is as follows:


WHAT DOCTYPE DO WE CHOOSE

The ideal situation is of course a strict DTD, but for most of us designers who are new to web standards, Transitional DTD (XHTML 1.0 Transitional) is currently the ideal choice (including this site, which also uses transitional DTD). Because this DTD also allows us to use presentation layer identifiers, elements and attributes, it is also easier to pass W3C code verification.

Note: The "identification and attributes of the presentation layer" mentioned above refer to those tags used purely to control performance, such as tables for typesetting, background color identification, etc. In XHTML, tags are used to represent structures, not to achieve presentation. The purpose of our transition is to ultimately separate data and presentation.

For example: a mannequin changes clothes. The model is like data, and the clothes are the form of expression. The model and the clothes are separated, so you can change clothes at will. In the original HTML4, data and presentation were mixed together, and it was very difficult to change the presentation form at once. Haha, it's a bit abstract. This concept needs to be gradually understood during the application process.

Supplement

The DOCTYPE declaration must be placed at the top of every XHTML document, above all code and markup.

For more details, please visit the W3C website

Day 2: What is a namespace

After the DOCTYPE is declared, the next code is:



Usually our HTML4.0 code is just , what is "xmlns" here?

This "xmlns" is the abbreviation of XHTML namespace, which is called the "namespace" statement. What is the role of namespace? Ajie's own understanding is:

Since xml allows you to define your own logo, the logo you define may be the same as the logo defined by others, but have different meanings. Errors can easily occur when files are exchanged or shared. To avoid this error, XML uses namespace declarations, which allow you to identify your identity through a URL pointing to it. For example:

Both Xiao Wang and Xiao Li have defined a identifier. If Xiao Wang's name space is "http://www.xiaowang.com" and Xiao Li's name space is "http ://www.xiaoli.com", then when the two documents exchange data, the identifier will not be confused because it belongs to a different name space.

A more popular explanation is: a namespace is to mark a document to tell others who this document belongs to. It's just that this "who" is replaced by a website address.

XHTML is a markup language that transitions from HTML to XML. It needs to comply with XML document rules, so it also needs to define a namespace. And because XHTML1.0 cannot customize the logo, its namespace is the same, which is "http://www.w3.org/1999/xhtml". It doesn't matter if you don't quite understand it yet, at this stage we just need to copy the code. The lang="gb2312" after

specifies that your document should be in Simplified Chinese.

Day 3: Define the language encoding

The third step is to define your language encoding, similar to this:


In order to be correctly interpreted by browsers and pass W3C code verification, all XHTML documents must declare the encoding language they use. We generally use gb2312 (Simplified Chinese). When making multi-language pages, we may also use Unicode, ISO-8859-1, etc., which can be defined according to your needs.

Usually this definition is enough. However, it should be added that XML documents do not define language encoding in this way. XML is defined as follows:



You can see similar statements in the first line of code on the homepage of Macromedia.com. This is also the definition method recommended by W3C. So why don't we just adopt this approach? The reason is that some browsers have incomplete support for standards and cannot correctly understand such definition methods, such as IE6/windows. Therefore, under the current transition plan, we still recommend using the meta method. Of course, you can write both ways.

Looking at the source code of this website, you will find that there is one more sentence where the language encoding is defined:



This is written for older browsers to ensure that various browsers can interpret the page correctly.

Note: At the end of the above declaration statement, you see a slash "/", which is different from our previous HTML4.0 code writing. The reason is that XHTML syntax rules require that all tags must have a beginning and an end. For example, and ,

and

, etc., for unpaired identifiers, it is required to add a space at the end of the identifier, followed by a "/". For example,
is written as
, and is written as . The reason for adding spaces is to prevent the browser from not recognizing the codes together.



Day 4: Calling style sheets

Use web standards to design websites. The transition method is mainly to use XHTML+CSS. CSS style sheets are essential. This requires all web designers to be proficient in CSS. If you have not used it before, start learning now. To create a website that complies with web standards, you cannot design beautiful pages without knowing CSS.

In fact, all aspects of performance need to be implemented with CSS. We used to use table for positioning and layout, but now we have to use p for positioning and layout. This is a change in the way of thinking, which is a bit uncomfortable at first. Haha, there will be resistance to any change. In order to enjoy the "benefits" brought by standards, it is worthwhile to give up some old traditional practices.

Externally calling style sheets

In the past, we usually used two methods to use style sheets:

Inline method on the page: that is, inserting the style sheet into the page Write it directly in the head area of ​​the page code. Similar to this:

External calling method: Write the style sheet in a separate .css file, and then call it with code similar to the following in the head area of ​​the page.

In a design that complies with web standards , we use the external calling method, and the benefits are self-evident. You can change the style of the page without modifying the page, only modifying the .css file. If all pages call the same style sheet file, then changing one style sheet file can change the styles of all files.

Double-table method to call the style sheet

Look at the original code of some standards-compliant sites. You may see that there are the following two sentences where the style sheet is called:



Why do you have to write it twice?

In fact, under normal circumstances, it is enough to use the external link method (that is, the first sentence). The double table call I use here is just an example. The "@import" command is used to enter the style sheet. The "@import" command is invalid in Netscape 4.0 browsers. In other words, when you want certain effects to be hidden in the Netscape 4.0 browser and displayed in 4.0 or above or other browsers, you can use the "@import" command method to call the style sheet.

Day 5: Other settings in the head area

These tips mainly focus on meta tag settings. In fact, they have little to do with complying with web standards. Just pay attention to adding them at the end. Just "/" to close the tag, but since this is an introductory tutorial, let's write it in more detail.

Favorites icon

If you add this site to your favorites, you can see that the IE icon before the favorites URL becomes a special icon for this site. To achieve this effect is very simple, first make a 16x16 icon, name it favicon.ico, and place it in the root directory. Then embed the following code into the head area:



< ;link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

Content prepared for search engines

The code is as follows, just replace it with the content of your own site:

Allow search robots to search all links in the site. If you want certain pages not to be searched, it is recommended to use the robots.txt method

Set site author information

< meta name="author" content="ajie@netease.com,阿杰" />

Set site copyright information



Brief introduction of the site (recommended)



Keywords of the site (recommended)



Let’s introduce this much first. Supplementary explanation, the previous 5 sections were all about the code of the head area, and the actual page content has not been mentioned at all. Haha, don’t worry, in fact, the head area is very important. You can know the designer by looking at the head code of a page. Is it professional enough?

Day 6: XHTML code specifications

Before starting formal content production, we must first understand the code specifications of web standards. Understanding these specifications can help you avoid detours and pass code verification as soon as possible.

1. All tags must have a corresponding closing tag

In the past, in HTML, you could open many tags, such as

and < ;li> instead of necessarily writing the corresponding

and to close them. But this is not legal in XHTML. XHTML requires a strict structure and all tags must be closed. If it is a separate unpaired tag, add a "/" at the end of the tag to close it. For example:


Web Designer

2. The names of all tag elements and attributes must be in lowercase

Unlike HTML, XHTML is case-sensitive, and < ;TITLE> is a different label. XHTML requires that all tag and attribute names must be lowercase. For example: <BODY> must be written as <body>. Mixed case is also not recognized. Usually the attribute name "onMouseOver" automatically generated by Dreamweaver must also be changed to "onmouseover". <br><br><strong>3. All XML tags must be nested reasonably </strong><br><br> Also because XHTML requires a strict structure, all nesting must be in order. Previously we Code written like this: <br><br><p><b></p>/b> must be modified to: <p><b></b>/p> <br> <br>That is to say, the nesting layer by layer must be strictly symmetrical. <br><br><strong>4. All attributes must be enclosed in quotation marks ""</strong><br><br>In HTML, you do not need to add quotation marks to attribute values, but in XHTML, they Must be quoted. For example: <br><br><height=80> must be changed to: <height="80"><br><br>In special cases, you need to use double quotes in the attribute value, you can use " , single quotes can use ', for example: <alt="say'hello'"> <br><br><strong>5. Use encoding to represent all < and & special symbols</strong><br/><br/>Any less than sign (<), which is not part of the label, must be encoded as & l t; <br/><br/>Any greater than sign (>), which is not part of the label, must be encoded as > <br><br>Any ampersand (&) that is not part of an entity must be encoded as & a m p; <br><br>Note: There are no spaces between the above characters <br><br>##. #6. Assign a value to all attributes<strong></strong><br>XHTML stipulates that all attributes must have a value, and if there is no value, it will repeat itself. For example:<br><br><td nowrap> < input type="checkbox" name="shirt" value="medium" checked> must be modified to: <td nowrap="nowrap"> <input type="checkbox" name="shirt" value="medium" checked="checked"> <br><br><br>7. Do not use "--" in the comment content <strong></strong><br> "--" can only occur at the beginning and end of XHTML comments end, that is, they are no longer valid in the content. For example, the following code is invalid: <br><br><!--Comment here----------Comment here. --> <br><br>Replace the internal dotted lines with equal signs or spaces <br><br><!--This is a comment============This is a comment- -> <br><br>Some of the above specifications may seem strange, but they are all aimed at making our code have a unified and unique standard to facilitate future data reuse <br><br>. <br><h2>Day 7: Introduction to CSS</h2> <p>After understanding the XHTML code specifications, we will proceed with CSS layout. First, let’s introduce some introductory knowledge of CSS. If you are already familiar with it, you can skip this section and go directly to the next section. <br><br>CSS is the abbreviation of Cascading Style Sheets. It is a simple mechanism for adding styles to web documents and belongs to the layout language of the presentation layer. <br><br><strong>1. Basic syntax specifications</strong><br><br>Analysis of a typical CSS statement: <br><br>p {COLOR:#FF0000;BACKGROUND:#FFFFFF} <br><br>We call "p" "selectors", indicating that we want to define a style for "p"; <br><br>The style declaration is written in a pair of curly brackets "{}";<br><br>COLOR and BACKGROUND are called "property", and different properties are separated by semicolons ";"; <br><br>"#FF0000" and "#FFFFFF" are the values ​​of the properties (value ). <br><br><strong>2. Color value</strong><br><br>Color value can be written in RGB value, for example: color: rgb(255,0,0), or hexadecimal Write, like the example above color:#FF0000. If the hexadecimal values ​​are repeated in pairs they can be abbreviated with the same effect. For example: #FF0000 can be written as #F00. However, it cannot be abbreviated if it does not repeat. For example, #FC1A1B must be filled with six digits. <br><br><strong>3. Define font</strong><br><br>Web standards recommend the following font definition method: <br><br>body { font-family: "Lucida Grande", Verdana, Lucida , Arial, Helvetica, Song Dynasty, sans-serif; } <br><br>The fonts are selected in the order listed. If the user's computer contains the Lucida Grande font, the document will be designated Lucida Grande. If not, it is designated as Verdana font, if there is no Verdana, it is designated as Lucida font, and so on,; <br><br>Lucida Grande font is suitable for Mac OS X; <br><br>Verdana font is suitable for all Windows system; <br><br>Lucida is suitable for UNIX users <br><br>"宋体" is suitable for simplified Chinese users; <br><br>If none of the listed fonts can be used, the default sans-serif The font can guarantee the call; <br><br><strong>4. Group selector</strong><br><br>When several elements have the same style attributes, they can call a statement together, and the elements are separated by commas. : p, td, li { font-size : 12px; } <br><br><strong>5. Derived selector</strong><br><br>You can use derived selectors to define child elements in an element Style, for example: <br><br>li strong { font-style: italic; font-weight: normal;} <br><br> is to define an italic but not bold style for the sub-element strong under li. <br><br><strong>6.id selector</strong><br><br> CSS layout is mainly implemented using the layer "p", and the style of p is defined through the "id selector". For example, we first define a layer <br><br><p id="menubar"></p><br><br> and then define it in the style sheet like this: <br><br>#menubar { MARGIN: 0px;BACKGROUND: #FEFEFE;COLOR: #666;} <br><br>where "menubar" is the id name you define. Note the "#" sign in front. <br><br>The id selector also supports derivation, for example: <br><br>#menubar p { text-align : right; margin-top : 10px; } <br><br>This method is mainly used Definition layers and those that are more complex and have multiple derived elements. <br><br><strong>7. Category selector </strong><br><br> Use a dot at the beginning to indicate the category selector definition in CSS, for example: <br><br>.14px {color : # f60 ;font-size:14px ;} <br><br>In the page, use the class="category name" method to call: <br><br><span class="14px">14px size font </span> <br><br>This method is relatively simple and flexible, and can be created and deleted at any time according to page needs. <br><br><strong>8. Define the link style </strong><br><br> Four pseudo-classes are used in CSS to define the link style, namely: a:link, a:visited, a: hover and a : active, for example: <br><br>a:link{font-weight : bold ;text-decoration : none ;color : #c00 ;}<br>a:visited {font-weight : bold ;text -decoration : none ;color : #c30 ;}<br>a:hover {font-weight : bold ;text-decoration : underline ;color : #f60 ;}<br>a:active {font-weight : bold ;text -decoration : none ;color : #F90 ;} <br><br>The above statements respectively define the styles of "links, visited links, when the mouse is over, and when the mouse is clicked". Note that you must write in the above order, otherwise the display may be different from what you expected. Remember they are in order "LVHA". <br><br>Haha, I feel a little dizzy after reading so much. In fact, there are many more grammatical specifications for CSS. Here are just some commonly used ones. After all, we are taking it step by step and it is impossible to become fat in one bite:)<br><br></p> <h2>Day 8: Introduction to CSS Layout</h2> <p>The biggest difference between CSS layout and traditional table layout is that the original positioning uses tables, through the spacing of the tables or using colorless and transparent GIF images To control the spacing of the text layout sections; now the layer (p) is used for positioning, and the spacing of the sections is controlled through the margin, padding, border and other attributes of the layer. <br><br><strong>1. Define p</strong><br><br>Analyze a typical definition of p example: <br><br>#sample{ MARGIN: 10px 10px 10px 10px;<br>PADDING :20px 10px 10px 20px; <br>BORDER-TOP: #CCC 2px solid;<br>BORDER-RIGHT: #CCC 2px solid;<br>BORDER-BOTTOM: #CCC 2px solid;<br>BORDER-LEFT: # CCC 2px solid;<br>BACKGROUND: url(images/bg_poem.jpg) #FEFEFE no-repeat right bottom;<br>COLOR: #666;<br>TEXT-ALIGN: center;<br>LINE-HEIGHT: 150 %; WIDTH:60%; } <br><br>The description is as follows: <br><br>The name of the layer is sample, and this style can be called by using <p id="sample"> on the page. <br><br>MARGIN refers to the blank space left outside the border of the layer, used for page margins or to create a gap with other layers. "10px 10px 10px 10px" respectively represents the four margins of "top, right, bottom and left" (clockwise direction). If they are all the same, they can be abbreviated to "MARGIN: 10px;". If the margin is zero, write "MARGIN: 0px;". Note: When the value is zero, except for the RGB color value 0% which must be followed by a percent sign, in other cases the unit "px" does not need to be followed. MARGIN is a transparent element and cannot define a color. <br><br>PADDING refers to the space between the border of the layer and the content of the layer. Like margin, specify the distance from the top, right, bottom and left borders to the content respectively. If they are all the same, they can be abbreviated to "PADDING:0px". To specify the left side individually, you can write "PADDING-LEFT: 0px;". PADDING is a transparent element and cannot define color. <br><br>BORDER refers to the border of the layer. "BORDER-RIGHT: #CCC 2px solid;" defines the right border color of the layer as "#CCC", the width as "2px", and the style as "solid" straight line. If you want a dotted line style, you can use "dotted". <br><br>BACKGROUND is the background that defines the layer. It is defined in two levels. First define the image background and use "url(../images/bg_logo.gif)" to specify the background image path; secondly define the background color "#FEFEFE". "no-repeat" means that the background image does not need to be repeated. If you need to repeat it horizontally, use "repeat-x", to repeat it vertically, use "repeat-y", and to repeat it to cover the entire background, use "repeat". The following "right bottom;" means that the background image starts from the lower right corner. If there is no background image, you can only define the background color BACKGROUND: #FEFEFE <br><br>COLOR is used to define the font color, which has been introduced in the previous section. <br><br>TEXT-ALIGN is used to define the arrangement of content in the layer, center is in the middle, left is in the left, and right is in the right. <br><br>LINE-HEIGHT defines the line height. 150% means that the height is 150% of the standard height. It can also be written as: LINE-HEIGHT:1.5 or LINE-HEIGHT:1.5em, which have the same meaning. <br><br>WIDTH is the width of the defined layer, which can be a fixed value, such as 500px, or a percentage, like "60%" here. It should be noted that this width only refers to the width of your content, and does not include margin, border and padding. However, it is not defined this way in some browsers, so you need to try more. <br><br>The following is the actual performance of this layer:<br><br><img src="http://www.csswebs.org/images/arrow.gif" alt="How to use CSS for web page layout" ><br>Demo page<br><br>We can see that the border is 2px gray, and the background image is not in the lower right Repeat, the distance between the content and the left border is 20px, the content is centered, and everything is as expected. Hoho, although it doesn’t look good, it is the most basic. If you master it, you will have learned half of the CSS layout technology. That's it, it's not difficult! (What is the other half? The other half is the positioning between layers. I will explain it step by step later.)<br><br><strong>2. CSS2 box model</strong><br><br>Since 1996 With the launch of CSS1 in 2016, the W3C organization recommended that all objects on the web page be placed in a box. Designers can control the properties of this box by creating definitions. These objects include paragraphs, lists, titles, and pictures. and layer<p>. The box model mainly defines four areas: content, padding, border and margin. The sample layer we talked about above is a typical box. For beginners, they are often confused about the levels, relationships, and mutual influences among margin, background-color, background-image, padding, content, and border. Here is a 3D schematic diagram of the box model, I hope it will be easier for you to understand and remember. <br><br><img src="http://www.csswebs.org/articles/Archiver/images/cssbox3d.gif" alt="How to use CSS for web page layout" ><br><br><strong>3. Use background processing for all auxiliary images </strong><br><br>Use XHTML+CSS layout, there is a technology that you are not used to at first , it should be said that the way of thinking is different from the traditional table layout, that is: all auxiliary pictures are realized with background. Similar to this: <br><br>BACKGROUND: url(images/bg_poem.jpg) #FEFEFE no-repeat right bottom; <br><br>Although it is possible to insert <img> directly into the content, this is not recommended. The "auxiliary pictures" here refer to pictures that are not part of the content to be expressed on the page, but are only used for decoration, interval, and reminder. For example: pictures in photo albums, pictures in picture news, and the 3D box model pictures above are all part of the content. They can be directly inserted into the page using the <img> element, while others are similar to logos, title pictures, and list prefixes. Images must be displayed using background or other CSS methods. <br><br><strong>There are two reasons for this: </strong><br><br><img src="http://www.csswebs.org/images/arrow.gif" alt="How to use CSS for web page layout" ><br> Completely separate performance from structure (refer to reading another article: "Understanding Performance "Separated from the structure"), using CSS to control all appearance and performance for easy revision. <br><br><img src="http://www.csswebs.org/images/arrow.gif" alt="How to use CSS for web page layout" ><br> Make the page more usable and more friendly. For example, if a blind person uses a screen reader, pictures implemented using background technology will not be read aloud. <br><br></p> <h2>Day 9: First CSS Layout Example</h2> <p>The next step is to actually design the layout. As with the traditional method, you first have to have a rough outline idea in your mind, and then draw it out in photoshop. You may see that most websites related to web standards are very simple, because web standards pay more attention to structure and content. In fact, it has no fundamental conflict with the beauty of web pages. You can design it however you want. The layout is implemented using the traditional table method. p can also be implemented. Technology has a maturation process. Think of p as the same tool as TABLE. How to use it depends on your imagination. <br><br>Note: In actual application, p is indeed not as convenient as a table in some places, such as the definition of background color. But everything has gains and losses, and the choice depends on your value judgment. Okay, no more wordy, let’s start: <br><br></p> <h2>1. Determine the layout </h2> <p>w3cn’s initial design sketch is as follows: <br><br><img src="http://www.csswebs.org/articles/Archiver/images/copy_w3cnhome.gif" alt="How to use CSS for web page layout" ><br><br><br>If you use the table design method, it is usually a three-row layout <br><img src="http://www.csswebs.org/articles/Archiver/images/layout_table.gif" alt="How to use CSS for web page layout" ><br>. If using p, I would consider using three columns for layout, like this <br><img src="http://www.csswebs.org/articles/Archiver/images/layout_css1.gif" alt="How to use CSS for web page layout" ><br>. <br><br></p> <h2>2. Define the body style </h2> <p> First define the body style of the entire page, the code is as follows: <br><br>body { MARGIN: 0px;<br> PADDING: 0px; <br>BACKGROUND: url(../images/bg_logo.gif) #FEFEFE no-repeat right bottom;<br>FONT-FAMILY: 'Lucida Grande','Lucida Sans Unicode','宋体', '新宋体',arial,verdana,sans-serif;<br>COLOR: #666;<br>FONT-SIZE:12px;<br>LINE-HEIGHT:150%; } <br><br>The above code The function was explained in detail in the previous day's tutorial, so everyone should understand it at a glance. The border margin is defined as 0; the background color is #FEFEFE, the background image is bg_logo.gif, the image is located in the lower right corner of the page, and does not repeat; the font size is defined as 12px; the font color is #666; the line height is 150%. <br><br></p> <h2>3. Define the main p</h2> <p> When I used CSS layout for the first time, I decided to use a fixed-width three-column layout (simpler than the adaptive resolution design, hoho, don’t say I’m lazy, implement a simple one first , increase your confidence! ). Define the width of the left, middle and right to be 200:300:280 respectively, which are defined in CSS as follows: <br><br>/*Define the left column style of the page*/<br>#left{ WIDTH:200px;<br>MARGIN: 0px;<br>PADDING: 0px;<br>BACKGROUND: #CDCDCD;<br>}<br>/*Define the column style on the page*/<br>#middle{ POSITION: absolute;<br>LEFT:200px; <br>TOP:0px;<br>WIDTH:300px;<br>MARGIN: 0px;<br>PADDING: 0px;<br>BACKGROUND: #DADADA;<br>}<br>/*Define the right column style of the page */<br>#right{ POSITION: absolute;<br>LEFT:500px;<br>TOP:0px;<br>WIDTH:280px;<br>MARGIN: 0px;<br>PADDING: 0px;<br> BACKGROUND: #FFF; } <br><br>Note: I used POSITION: absolute; to define p in the middle column and the right column, and then defined LEFT:200px;TOP:0px; and LEFT:500px;TOP:0px respectively. ;This is the key to this layout, I used absolute positioning of the layers. Define the middle column to be 200px from the left border of the page and 0px from the top; define the right column to be 500px from the left border of the page and 0px from the top;. <br><br>The code of the entire page at this time is: <br><br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br><html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312"><br>< ;head><br><title>Welcome to the new "Web Designer": web standard tutorial and promotion












Left column of page


Middle column of page






At this time, the effect of the page can only be seen in three parts juxtaposed gray rectangles, and a background image. But I want the height to be full screen, what should I do?

4.100% adaptive height?

In order to keep the three columns with the same height, I tried to set "height:100 in #left, #middle and #right %;", but found that there was no expected adaptive height effect at all. After some attempts, I had to give each p an absolute height: "height:1000px;", and as the content increases, I need to constantly correct this value. Is there no way to adjust the height? As Ajie's own study deepened, he discovered a flexible solution. In fact, there is no need to set 100% at all. We have been too deeply imprisoned by table thinking. This method will be introduced in detail in the next section of study.

Day 10: Adaptive height

If we want to add a footer line at the end of the 3-column layout to put information such as copyright. I encountered the problem of having to align the bottom of 3 columns. In the table layout, we use the method of nesting large tables into small tables, which can easily align the three columns; with the p layout, the three columns are scattered independently and the content is of different heights, making it difficult to align. In fact, we can completely nest p, put three columns into one p, and achieve bottom alignment. Here is an implementation example (a white background box simulates a page):

The main code of the page in this example is as follows:








Specific style sheet All are written in the corresponding sections. The key point is that the #mainbox layer is nested in three layers: #menu, #sidebar and #content. When the content of #content increases, the height of #content will increase, and the height of #mainbox will also expand, and the #footer layer will automatically move down. This achieves a high degree of adaptability.

It is also worth noting that #menu and #content are floating on the right side of the page "FLOAT: right;", #sidebar is floating on the left side of the #menu layer "FLOAT: left;", this is floating Method positioning, you can also use absolute positioning to achieve such an effect.

There is another problem with this method, that is, the background of the sidebar #sidebar cannot be 100%. The general solution is to fill it with the body's background color. (The background color of #mainbox cannot be used, because the background color of #mainbox is invalid in browsers such as Mozilla.)

Okay, the main framework has been built, and the remaining work is just to add bricks and tiles to it. If you want to try other layouts, it is recommended to read the following articles:


Day 11: Menu without tables

The layout was initially set up, and I started filling in the content. The first is to define the logo image:

Style sheet: #logo {MARGIN: 0px;padding:0px;WIDTH: 200px;HEIGHT:80px;}
Page code:


The above code should be easy to understand now. First define a logo layer in CSS, and then call it on the page. It should be noted that in order to make web pages more usable, web standards require everyone to add an alt attribute to all images that are formal content. This alt attribute is used to describe the function of the image (display replacement text when the image cannot be displayed), so don't just write a meaningless image name.

The next step is to define the menu.

1. Menu without tables (vertical)

Let’s first look at the final effect of the menu: demo page

Usually we can at least nest it A 2-layer table is used to implement such a menu. The interval line is implemented by setting the background color in td and inserting a 1px high transparent GIF image; the alternating effect of the background color is implemented by using the onmouseover event of td. But if you look at the page code of this menu, you will see that there are only the following sentences:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template