Website Construction with web standards for 8th days: CSS layout entry (2)

Source: Internet
Author: User

Now we need to design the layout. Like the traditional method, you must first have a rough idea of the outline in your mind, and then use Photoshop to draw it out. You may see that most websites related to web standards are simple, because web standards focus more on the structure and content. In fact, they do not fundamentally conflict with the appearance of web pages. You can design them as you want, la s are implemented using the traditional table method, and Div can also be used. There is a mature process of technology. It depends on your imagination to use Div as a tool like table.

Note: in actual application, div is not as convenient as a table in some places, such as the definition of the background color. But there are gains and losses in everything. The trade-off lies in your value judgment. Well, let's start:

1. Determine the Layout

The initial design sketch of w3cn is as follows:

The table design method is generally used for the layout of the top, bottom, and bottom three rows.

. If div is used, I want to use three columns for layout.
.

2. Define the body style

First, define the style of the whole page body. The Code is as follows:

Body {margin: 0px;

Padding: 0px;

Background: URL (../images/bg_logo.gif) # fefefefe no-repeat right bottom;

Font-family :\\\ 'lucida Grande \\\ ', \\\ 'lucida sans Unicode \\\', \\\ '\\\', \\\' \\\ ', Arial, verdana, sans-serif;

Color: #666;

Font-size: 12px;

Line-Height: 150%;} the above Code is described in detail in the previous day's tutorial. Set the border to 0. The background image is bg_logo.gif, and the image is located in the lower right corner of the page. The font size is 12 PX, the font color is #666, And the row height is 150%.

3. define the main Div

When I first used CSS layout, I decided to adopt a fixed-width three-column layout (simpler than adaptive resolution design, Hoho, not to mention my laziness. First, it was easy to implement and increased confidence !). Define the width of the left center and right sides as 200: 300: 280, as defined in CSS:

/* Define the style of the left column on the page */

# Left {width: 200px;

Margin: 0px;

Padding: 0px;

Background: # cdcdcd;

}

/* Define the column style on the page */

# Middle {position: absolute;

Left: 200px;

Top: 0px;

Width: 300px;

Margin: 0px;

Padding: 0px;

Background: # dadada;

}

/* Define the style of the right column on the page */

# Right {position: absolute;

Left: 500px;

Top: 0px;

Width: 280px;

Margin: 0px;

Padding: 0px;

Background: # FFF;} note: In the definition, I used position: absolute; for the column and right column Div, and then defined left: 200px; top: 0px; and left: 500px; top: 0px; this is the key to this layout. I use the absolute positioning of the layer. Define the distance between the middle column and the left border of the page, PX from the top, and PX from the Left Border and 0 px from the top of the page ;.

The code for the entire page is:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml" lang = "gb2312">

<Head>

<Title> welcome to the new web designer: Web Standard tutorial and promotion </title>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>

<Meta http-equiv = "content-language" content = "gb2312"/>

<Meta content = "all" name = "Robots"/>

<Meta name = "author" content = "Ajie (AT) netease.com, "/>

<Meta name = "Copyright" content = "www.w3cn.org"/>

<Meta name = "Description" content = "New web designer, Web Standard tutorial site, promote the application of Web standards in China."/>

<Meta content = "Web standard, tutorial, web, standards, XHTML, CSS, usability, accessibility" name = "keywords"/>

<LINK rel = "icon" href = "/favicon. ICO" type = "image/X-icon"/>

<LINK rel = "shortcut icon" href = "http://www.w3cn.org/favicon.ico" type = "image/X-icon"/>

<LINK rel = "stylesheet" REV = "stylesheet" href = "CSS/style01.css" type = "text/CSS" Media = "all"/>

</Head>

<Body>

<Div id = "Left"> left column </div>

<Div id = "Middle"> columns on the page </div>

<Div id = "right"> right column </div>

</Body>

</Html> in this case, only three gray Rectangles and a background image are displayed. But what if I want the height to be full?

4.100% adaptive height?

To keep the three columns at the same height, I tried to set "height: 100%;" in # Left, # Middle, and # Right, but found that there was no expected adaptive height effect. After some attempts, I had to give each Div an absolute height: "height: 1000px;", and as the content increases, the value needs to be constantly corrected. Is there no way to adapt to the height? With the deep learning of Alibaba Cloud, Alibaba Cloud has found a flexible solution. In fact, we don't need to set 100%. We have been banned by table thinking too deeply, this method is described in detail in the next section.

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.