Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

How to Center a DIV

A DIV is a block element which means that it contains an embedded carriage return before and another embedded carriage return after it is rendered on your webpage. Therefore it delineates a horizontal section or division all the way across it's containing element, which my be the browser window. However, if you specify a width for a div, it may display less wide than it's containing element, in which case you may want to center it.

One way to center a div is to place it within HTML <center></center> tags. This tag dates back to HTML version 1, but is now deprecated, which means it's not guaranteed to work all browsers. However, it still works in all important browsers today and deprecated tags are rarely removed to avoid breaking older websites.

The current proper way to center a div is to use CSS to set both its margin-left and margin-right properties to auto. The code for this is shown below.

<div style="width:200px; height:200px; margin-left:auto; margin-right:auto;"></div>

More Easy Cascading Style Sheets:
• Create a Cool Picture Frame Effect with CSS
• Create a No Image Rollover Button or Badge
• The CSS Box Model
• Easy Floating Menu Code
• CSS Arts and Crafts - Create a Graphic Cube Using the CSS3 Transform Property
• Code for Horizontal Drop-down Menu Bar
• Basic Introduction to Simple Responsive Design With Code
• Easy CSS Popup Windows
• Add Style to Your Blockquotes
• Make a Fixed-width Variable-height Round Cornered Box

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2018 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268