HTML developmen...login
HTML development manual
author:php.cn  update time:2022-04-11 17:45:33

HTML layout



Web page layout is very important to improve the appearance of the website.

Please design your web page layout carefully.


Online example

Web page layout using <div> element
How to use <div> element to add layout.

Webpage layout using <table> element
How to add layout using <table> element.


Website Layout

Most websites arrange content into multiple columns (just like a magazine or newspaper).

Most websites can use the <div> or <table> elements to create multiple columns. CSS is used to position elements or create backgrounds and colorful looks for pages.

lamp.jpgAlthough we can use the HTML table tag to design a beautiful layout, the table tag is not recommended to be used as a layout tool - Tables are not layout tools.


HTML Layout - Using the <div> element

The div element is a block-level element used to group HTML elements.

The following example uses five div elements to create a multi-column layout:

Example

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<div id="container" style="width:500px">

<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">主要的网页标题</h1></div>

<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>菜单</b><br>
HTML<br>
CSS<br>
JavaScript</div>

<div id="content" style="background-color:#EEEEEE;height:200px;width:400px;float:left;">
内容在这里</div>

<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
版权 © php.cn</div>

</div>
 
</body>
</html>

Run Example»

Click the "Run Instance" button to view the online instance

The above HTML code will produce the following results:

000.png


HTML Layout - Using Tables

Using the HTML <table> tag is an easy way to create layouts.

Most sites can use the <div> or <table> elements to create multiple columns. CSS is used to position elements or create backgrounds and colorful looks for pages.

lamp.jpgEven though you can use HTML tables to create beautiful layouts, tables are designed to present tabulated data - tables are not layout tools !

The following example uses a table with three rows and two columns - the first and last rows use the colspan attribute to span two columns:

Example

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<table width="500" border="0">
<tr>
<td colspan="2" style="background-color:#FFA500;">
<h1>主要的网页标题</h1>
</td>
</tr>

<tr>
<td style="background-color:#FFD700;width:100px;">
<b>菜单</b><br>
HTML<br>
CSS<br>
JavaScript
</td>
<td style="background-color:#eeeeee;height:200px;width:400px;">
内容在这里</td>
</tr>

<tr>
<td colspan="2" style="background-color:#FFA500;text-align:center;">
版权 © php.cn</td>
</tr>
</table>

</body>
</html>

Run Instance»

Click the "Run Instance" button to view the online instance

The above HTML code will produce the following results:

001.png

HTML Layout - Helpful Tips

Tip: The biggest advantage of using CSS is that the site will be easier to maintain if the CSS code is stored in an external style sheet. By editing a single file, you can change the layout of all pages. To learn more about CSS, visit our CSS tutorials.

Tip: Since creating advanced layouts can be time-consuming, using templates is a quick option. There are many free website templates available through search engines (you can use these pre-built website layouts and optimize them).


HTML Layout Tags

Define document block, block-levelDefine span, used to combine inline elements in the document.
TagDescription
## <div>
<span>