Você está na página 1de 4

4/4/13

HTML Layouts

HTML Layouts
Previous
Web page layout is very important to make your website look good. Design your webpage layout very carefully.

Next Chapter

Try it Yourself - Examples


Web page layout using <div> elements How to add layout using <div> elements. Web page layout using <table> elements How to add layout using <table> elements.

Website Layouts
Most websites have put their content in multiple columns (formatted like a magazine or newspaper). Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages. Even though it is possible to create nice layouts with HTML tables, tables were designed for presenting tabular data - NOT as a layout tool!

HTML Layouts - Using <div> Elements


The div element is a block level element used for grouping HTML elements. The following example uses five div elements to create a multiple column layout, creating the same result as in the previous example:

Example
< ! D O C T Y P Eh t m l > < h t m l > < b o d y > < d i vi d = " c o n t a i n e r "s t y l e = " w i d t h : 5 0 0 p x " > < d i vi d = " h e a d e r "s t y l e = " b a c k g r o u n d c o l o r : # F F A 5 0 0 ; " > < h 1s t y l e = " m a r g i n b o t t o m : 0 ; " > M a i nT i t l eo fW e bP a g e < / h 1 > < / d i v > < d i vi d = " m e n u "s t y l e = " b a c k g r o u n d c o l o r : # F F D 7 0 0 ; h e i g h t : 2 0 0 p x ; w i d t h : 1 0 0 p x ; f l o a t : l e f t ; " > < b > M e n u < / b > < b r > H T M L < b r > C S S < b r > J a v a S c r i p t < / d i v > < d i vi d = " c o n t e n t "s t y l e = " b a c k g r o u n d c o l o r : # E E E E E E ; h e i g h t : 2 0 0 p x ; w i d t h : 4 0 0 p x ; f l o a t : l e f t ; " >
w3schools.com/html/html_layout.asp 1/4

4/4/13

HTML Layouts

C o n t e n tg o e sh e r e < / d i v > < d i vi d = " f o o t e r "s t y l e = " b a c k g r o u n d c o l o r : # F F A 5 0 0 ; c l e a r : b o t h ; t e x t a l i g n : c e n t e r ; " > C o p y r i g h tW 3 S c h o o l s . c o m < / d i v > < / d i v > < / b o d y > < / h t m l >
Try it yourself The HTML code above will produce the following result:

Main Title of Web Page


Menu HTML CSS JavaScript Content goes here

Copyright W3Schools.com

HTML Layouts - Using Tables


A simple way of creating layouts is by using the HTML <table> tag. Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages. Using <table> to create a nice layout is NOT the correct use of the element. The purpose of the <table> element is to display tabular data! The following example uses a table with 3 rows and 2 columns - the first and last row spans both columns using the colspan attribute:

Example
< ! D O C T Y P Eh t m l > < h t m l > < b o d y > < t a b l ew i d t h = " 5 0 0 "b o r d e r = " 0 " > < t r > < t dc o l s p a n = " 2 "s t y l e = " b a c k g r o u n d c o l o r : # F F A 5 0 0 ; " > < h 1 > M a i nT i t l eo fW e bP a g e < / h 1 > < / t d > < / t r >
w3schools.com/html/html_layout.asp 2/4

4/4/13

HTML Layouts

< t r > < t ds t y l e = " b a c k g r o u n d c o l o r : # F F D 7 0 0 ; w i d t h : 1 0 0 p x ; " > < b > M e n u < / b > < b r > H T M L < b r > C S S < b r > J a v a S c r i p t < / t d > < t ds t y l e = " b a c k g r o u n d c o l o r : # E E E E E E ; h e i g h t : 2 0 0 p x ; w i d t h : 4 0 0 p x ; " > C o n t e n tg o e sh e r e < / t d > < / t r > < t r > < t dc o l s p a n = " 2 "s t y l e = " b a c k g r o u n d c o l o r : # F F A 5 0 0 ; t e x t a l i g n : c e n t e r ; " > C o p y r i g h tW 3 S c h o o l s . c o m < / t d > < / t r > < / t a b l e > < / b o d y > < / h t m l >
Try it yourself The HTML code above will produce the following result:

Main Title of Web Page

Menu HTML CSS JavaScript

Content goes here

Copyright W3Schools.com

HTML Layout - Useful Tips


Tip: The biggest advantage of using CSS is that, if you place the CSS code in an external style sheet, your site becomes MUCH EASIER to maintain. You can change the layout of all your pages by editing one file. To learn more about CSS, study our CSS tutorial. Tip: Because advanced layouts take time to create, a quicker option is to use a template. Search Google for free website templates (these are pre-built website layouts you can use and customize).

HTML Layout Tags


Tag <div> <span>
w3schools.com/html/html_layout.asp

Description Defines a section in a document (block-level) Defines a section in a document (inline)


3/4

4/4/13

HTML Layouts

Previous

Next Chapter

w3schools.com/html/html_layout.asp

4/4

Você também pode gostar