Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Center Center a Div Re: Center Center a Div

#116968
redhornet
Participant

About the horizontal centering you may use margin:0 auto; only if you set some width of your div element; You may also use more clever way with position relative. I Use this approach when have to centering ul elements which is with display:inline by default.
The idea is:

.holder {
float: left;
left: 50%;
position: relative;
}
.holder > div {
float: left;
left: -50%;
position: relative;
}

the parent of .holder also must be with position relative.
You may use this approach for vertical centering.
I hope you catch the idea (: