Anda di halaman 1dari 3

7/21/2014 CSS Styling Tables

http://www.w3schools.com/css/css_table.asp 1/3
REFERENCES | EXAMPLES | FORUM
CSS Tutorial
CSS HOME
CSS Introduction
CSS Syntax
CSS Selectors
CSS How To
CSS Backgrounds
CSS Text
CSS Fonts
CSS Links
CSS Lists
CSS Tables
CSS Box Model
CSS Border
CSS Outline
CSS Margin
CSS Padding
CSS Dimension
CSS Display
CSS Positioning
CSS Floating
CSS Align
CSS Combinators
CSS Pseudo-class
CSS Pseudo-element
CSS Navigation Bar
CSS Image Gallery
CSS Image Opacity
CSS Image Sprites
CSS Media Types
CSS Attr Selectors
CSS3 Tutorial
CSS3 Introduction
CSS3 Borders
CSS3 Backgrounds
CSS3 Gradients
CSS3 Text Effects
CSS3 Fonts
CSS3 2D Transforms
CSS3 3D Transforms
CSS3 Transitions
CSS3 Animations
CSS3 Multiple Columns
CSS3 User Interface
CSS Summary
CSS Examples
CSS Examples
CSS Quiz
CSS Certificate
CSS References
CSS Reference
CSS Selectors
CSS Reference Aural
CSS Web Safe Fonts
CSS Units
CSS Colors
CSS Color Values
CSS Color Names
CSS Color HEX
Previous Next Chapter
CSS Tables
The look of an HTML table can be greatly improved with CSS:
Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Berglunds snabbkp Christina Berglund Sweden
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
Kniglich Essen Philip Cramer Germany
Laughing Bacchus Winecellars Yoshi Tannamuri Canada
Magazzini Alimentari Riuniti Giovanni Rovelli Italy
North/South Simon Crowther UK
Paris spcialits Marie Bertrand France
The Big Cheese Liz Nixon USA
Vaffeljernet Palle Ibsen Denmark
Table Borders
To specify table borders in CSS, use the border property.
The example below specifies a black border for table, th, and td elements:
Example
table, th, td {
border: 1px solid black;
}
Try it yourself
Notice that the table in the example above has double borders. This is because both the table and the th/td elements
have separate borders.
To display a single border for the table, use the border-collapse property.
Collapse Borders
The border-collapse property sets whether the table borders are collapsed into a single border or separated:
Example
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
Try it yourself
Table Width and Height
Width and height of a table is defined by the width and height properties.
The example below sets the width of the table to 100%, and the height of the th elements to 50px:
Search w3schools.com:
WEB HOSTING
UK Reseller Hosting
cPanel Hosting
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free HTML5 Templates
W3SCHOOLS EXAMS
HTML, CSS, JavaScript,
PHP, jQuery, XML, and
ASP Certifications
SHARE THIS PAGE
WEB RESOURCES
Web Statistics
Web Validation
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
Select Language
7/21/2014 CSS Styling Tables
http://www.w3schools.com/css/css_table.asp 2/3
Example
table {
width: 100%;
}
th {
height: 50px;
}
Try it yourself
Table Text Alignment
The text in a table is aligned with the text-align and vertical-align properties.
The text-align property sets the horizontal alignment, like left, right, or center:
Example
td {
text-align: right;
}
Try it yourself
The vertical-align property sets the vertical alignment, like top, bottom, or middle:
Example
td {
height: 50px;
vertical-align: bottom;
}
Try it yourself
Table Padding
To control the space between the border and content in a table, use the padding property on td and th elements:
Example
td {
padding: 15px;
}
Try it yourself
Table Color
The example below specifies the color of the borders, and the text and background color of th elements:
Example
table, td, th {
border: 1px solid green;
}
th {
background-color: green;
color: white;
}
Try it yourself
More Examples
Make a fancy table
This example demonstrates how to create a fancy table.
7/21/2014 CSS Styling Tables
http://www.w3schools.com/css/css_table.asp 3/3
Previous Next Chapter
Set the position of the table caption
This example demonstrates how to position the table caption.
REPORT ERROR | HOME | TOP | PRINT | FORUM | ABOUT | ADVERTISE WITH US
Top 10 Tutorials
HTML Tutorial
HTML5 Tutorial
CSS Tutorial
CSS3 Tutorial
JavaScript Tutorial
jQuery Tutorial
SQL Tutorial
PHP Tutorial
ASP.NET Tutorial
XML Tutorial
Top 10 References
HTML/HTML5 Reference
CSS 1,2,3 Reference
CSS 3 Browser Support
JavaScript
HTML DOM
XML DOM
PHP Reference
jQuery Reference
ASP.NET Reference
HTML Colors
Top 10 Examples
HTML Examples
CSS Examples
JavaScript Examples
HTML DOM Examples
PHP Examples
jQuery Examples
XML Examples
XML DOM Examples
ASP Examples
SVG Examples
Web Certificates
HTML Certificate
HTML5 Certificate
CSS Certificate
JavaScript Certificate
jQuery Certificate
PHP Certificate
XML Certificate
ASP Certificate
Color Picker
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples
are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use,
cookie and privacy policy. Copyright 1999-2014 by Refsnes Data. All Rights Reserved.

Anda mungkin juga menyukai