how to place a div in center

vishal455648

New Member
Messages
4
Reaction score
0
Points
0
I have made a simple youtube downloader(http://downvid.co.cc)I want to place google +1 and facebook like in center.I have done

Code:
margin-left: 48%;

but it does not in exactly centre.I have tried text-alignment: center but it does not work.please help.
 

Anna

I am just me
Staff member
Messages
11,750
Reaction score
581
Points
113
to center a div, it first need a set size, and then margin left and right set to auto, like:
Code:
width: 200px;
margin-left: auto;
margin-right: auto;
The auto parameter makes sure the margin has the same value on the left and right side of the div, as you probably noticed setting margin-left: 48%; only shifts the div to have it's left side somewhere near the middle of the page. In theory it would work if you did something like:
Code:
width: 4%;
margin-left: 48%;
margin-right: 48%;
This example would theoretically work (I say theoretically due to the fact that if you mix in a border it would possibly fail on some browsers) since you tell the browser how to use the full width of the page, and would give you a dynamic width on the div, with a fixed with, you need to use the auto parameter for left and right margins.
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
The first example was the better, although I would have said margin: 0 auto;
 
Top