I've an image of width 591px and below that image I've to write Home, About and Contact. I want Home, About and Contact to be centered below the image. I'm using the html and css codes as shown below but I'm not getting the desired result. I'm getting Home, About and Contact starting from left only. They are not getting centered. Please help.
Ah ok I see. It's because the width of the button wrap is the size of the slider itself. If you set the width of #button-wrap you will notice it starting to center.
I changed the width of #button-wrap to 150px and got Home, About and Contact centered. But can't we have a better way. Suppose that I have to add another word, say Services, to Home, About and Contact then I'll have to again change the width to may be 200px or so. I think there should be a better approach than this.
That sounds like something that should work. One or two things in the area might need to be adjusted. You have a solution though so you should probably stick with it.
@noahgelman .... thanks.....ur solution is working perfectly in chrome and mozilla......in ie6 they are not coming exactly in the center, they are getting shifted more towards right side....u also said that you will not rely on tables....please tell the reason.....are there any issues?
My HTML Code:
My CSS Code:
CSS Method
Change your original CSS to this:
That should work. However, it won't work in IE6 and 7. It will be aligned left instead.
The other way would be a javascript method.
Change your original CSS to this:
And add this within your <head> section:
What that is basically doing is setting #button-wrap's width to whatever it is at that point in time. The margin: 0 auto should then center it.
Try this:
That sounds like something that should work. One or two things in the area might need to be adjusted. You have a solution though so you should probably stick with it.