View Full Version : Problem with Center Attribute and Bgcolor Attribute

07-07-2007, 11:59 PM
When I try and center an image or Input field it will remain left justified, why does this happen? The align="left" and the align="right" both work but center does not.
Also, How do you use bgcolor properly? I have in a bit of code: <h2 align="left" bgcolor="red">Left aligned heading</h2> But the color red does not appear behind the text. How do you use the attribute bgcolor the correct way? Any help would be greatly appreciated. Thanks.

07-08-2007, 12:10 AM
You don't use the bgcolor attribute at all, use CSS instead. Like this:

<style type="text/css">
h2 {
background: #f00;
color: #000;

That goes between <head> and </head>.

As to your centering issue. Try wrapping everything in a class which you call "center". Like this:

.center {
margin: 0 auto;
width: 400px;

Doesn't necessarily have to be 400 px just an example.

07-08-2007, 12:23 AM
Thanks that clears up the issue.