CSS How To Align Center A Div Make Div Tag Align Center Css
CSS How To Align Center A Div Make Div Tag Align Center Css
Post Description:
Post Tags: css, how, to, align, center, a, div, make, div, tag, align, center, css
This Post Has Been Viewed 2460 Times Since Sun Mar 02, 2008 12:49 pm Posted By
hostman with 6 replies
Next Post »»
make css links all same making link in css behave the same
| CSS How To Align Center A Div Make Div Tag Align Center Css |
|
today i had a css file and i was trying to align a div i had and i wanted to make it align center
but there is not center propertie there is only align text or float left or float right but no float center so how can you make a div section align to cneter? well, its easy all you have to do is use this:
CSS CODE EXAMPLE
margin:0 auto;
its that simple
this the actual code i had in my .css file:
.main {
padding: 10px;
width: 798px;
border:1px solid #ccc;
border-width: 0 1px 1px 1px 1px;
margin:0 auto;
}
Leave Your Comments [ dejar commentarios ]
Comments and replies About CSS How To Align Center A Div Make Div Tag Align Center Css
:: 1 :: #50216 - Reply By yunhaihuang On Mon Apr 14, 2008 7:24 pm
hello! i want to align my div in the middle of the screen, but the above code doesn't work.
:: 2 :: #55558 - Reply By David On Wed May 28, 2008 2:55 pm
thanks, this saved me from a few hours of headaches.
:: 3 :: #63714 - Reply By Rob On Mon Jul 28, 2008 11:27 am
this was a big time problem for me that had an easy solution!!
an easy solution with 2 minutes work.
cheers,
:: 4 :: #68059 - Reply By Wardak On Mon Aug 25, 2008 6:12 am
this code does not align a div in the middle. what you actually for your own website is that you put the following div css
.main {
width: 980px;background-color: #252525; float: left;margin-top: 25px; }
inside a table that is aligned to be centered. so, basically you're using the table's centering feature to center your left floated div simply as a content. you're not doing anythign through div or css for that matter. the piece of css code you offered doesn't not anythign about centering a div in the middle.
:: 5 :: #68061 - Reply By hostman On Mon Aug 25, 2008 6:29 am
no, not using on wallpaperama. wallpaperama still has older code, im hoping to update soon, i just haven't gotten time to do it. i guess im just being lazy.
anywayz, i have other projects where i do use it. for example, if you go to
http://www.jesuswillcome.com you will see the the main div there is called mbox. you will see all the content contained within the mbox div and its aligned centered.
the css code is here: http://www.jesuswillcome.com/theme/webune/style/webune.css
when you look at the code, you will find this code:
.mbox{
border:1px solid #656565;
margin:0 auto;
background-color:#f9f9f9;
width: 958px;
}
:: 6 :: #68562 - Reply By Simon On Fri Aug 29, 2008 4:50 am
you also need to place text-align: center; in your body tag like this:
body
{ text-align: center;
margin: 0 auto; }
.div
{ margin: 0 auto; }