CSS Horizontal Align
CSS Horizontal Align
Search w3schools.c Select Language HOME HTML C SS JAVASC RIPT JQUERY XML ASP.NET PHP SQL MORE...
R EFER ENC ES | EXAMPLES
Get Certified
Study Web Technologies and get a diploma at w3schools.com
CSS Basic
CSS HOME CSS Introduction CSS Syntax CSS Id & Class CSS How To
CSS Styling
Styling Backgrounds Styling Text Styling Fonts Styling Links Styling Lists Styling Tables
In CSS, several properties are used to align elements horizontally. Aligning Block Elements
A block element is an element that takes up the full width available, and has a line break before and after it. Examples of block elements: <h1> <p> <div> For aligning text, see the CSS Text chapter. In this chapter we will show you how to horizontally align block elements for layout purposes.
Related Searches: Container Div HTML And XHTML Font Color W eb Design Services Logo Design Services Block Elements Layout W ith CSS W eb Publishing
CSS Advanced
CSS Grouping/Nesting CSS Dimension CSS Display CSS Positioning CSS Floating CSS Align CSS Pseudo-class CSS Pseudo-element CSS Navigation Bar CSS Image Gallery CSS Image Opacity CSS Image Sprites CSS Media Types CSS Attribute Selectors CSS Summary
Example
. c e n t e r { m a r g i n l e f t : a u t o ; m a r g i n r i g h t : a u t o ; w i d t h : 7 0 % ; b a c k g r o u n d c o l o r : # b 0 e 0 e 6 ; }
Try it yourself Tip: Aligning has no effect if the width is 100%.
CSS Examples
CSS Examples CSS Quiz CSS Certificate
Note: In IE5 there is a margin handling bug for block elements. To make the example above work in IE5, add some extra code. Try it yourself
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
Example
. r i g h t { p o s i t i o n : a b s o l u t e ; r i g h t : 0 p x ; w i d t h : 3 0 0 p x ; b a c k g r o u n d c o l o r : # b 0 e 0 e 6 ; }
Try it yourself Note: Absolute positioned elements are removed from the normal flow, and can overlap elements.
w3schools.com/css/css_align.asp
1/3
8/4/13
Example
b o d y { m a r g i n : 0 ; p a d d i n g : 0 ; } . c o n t a i n e r { p o s i t i o n : r e l a t i v e ; w i d t h : 1 0 0 % ; } . r i g h t { p o s i t i o n : a b s o l u t e ; r i g h t : 0 p x ; w i d t h : 3 0 0 p x ; b a c k g r o u n d c o l o r : # b 0 e 0 e 6 ; }
Try it yourself
Example
. r i g h t { f l o a t : r i g h t ; w i d t h : 3 0 0 p x ; b a c k g r o u n d c o l o r : # b 0 e 0 e 6 ; }
Try it yourself
Example
b o d y { m a r g i n : 0 ; p a d d i n g : 0 ; } . r i g h t { f l o a t : r i g h t ; w i d t h : 3 0 0 p x ; b a c k g r o u n d c o l o r : # b 0 e 0 e 6 ; }
Try it yourself
Previous
Next Chapter
w3schools.com/css/css_align.asp
2/3
8/4/13
Top 10 Tutorials
HTML Tutorial HTML5 Tutorial C SS Tutorial C SS3 Tutorial JavaScript Tutorial jQuery Tutorial SQL Tutorial PHP Tutorial ASP.NET Tutorial XML Tutorial
Top 10 References
HTML/HTML5 Reference C SS 1,2,3 Reference C SS 3 Browser Support JavaScript HTML DOM XML DOM PHP Reference jQuery Reference ASP.NET Reference HTML C olors
Examples
HTML Examples C SS Examples XML Examples JavaScript Examples HTML DOM Examples XML DOM Examples AJAX Examples ASP.NET Examples Razor Examples ASP Examples SVG Examples
Quizzes
HTML Quiz HTML5 Quiz XHTML Quiz C SS Quiz JavaScript Quiz jQuery Quiz XML Quiz ASP Quiz PHP Quiz SQL Quiz
Color Picke
Statistics
RE P O RT E RRO R
HO ME
TO P
P RI N T
FO RU M
A BO U T
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 and privacy policy. C opyright 1999-2013 by Refsnes Data. All Rights Reserved.
w3schools.com/css/css_align.asp
3/3