Jump to content

Centering Without <center>


bw83

Recommended Posts

So I have been going through the tutorials and I am using it for practice and making changes as I am going to a site I am playing with for fun and learning. I noticed in http://www.w3schools.com/TAGS/tag_center.asp that portion of the tutorial it says not to use the <center> but instead use CSS for centering. Now I think I understand where that link goes to and how it talks about aligning text but I am confused if it is not text that I want to align. Here are the two pages one aligned with <center> how I originally had it and one that I am switching over stuff to a CSS stylesheet. http://www.bw83.com/vampwars/index.php (using the <center> )http://www.bw83.com/vampwars/home.php (using stylesheets)Now you can see that the navigation menu in the top is centered in the one and just positioned to the left of the DIV in the other. What do I need to add to my CSS sheet to align the navigation over since it is not just simple text?

Link to comment
Share on other sites

Setting the left and right margins of an element to "auto" will center it, relatively to its container's actual dimensions.So, to center an element, add

margin:0 auto;

to its CSS.

Link to comment
Share on other sites

Thanks!!! It took me a few minutes of playing around with it because I kept trying to add that line into the CSS of parent Div instead of that of the element itself. (Just incase you check I didnt update it on my webserver on my local WAMP just to save time for now, but thank you very much)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...