Hi, I'm having trouble because I have a div I want to center and what I have
usually been told to do is this:
width: 700px;
margin-left: auto;
margin-right: auto;
the trouble is, this is for if you want the div to be a fixed width. I want the div
to adjust its size based on the text in the div, and still be centered. I tried:
width: auto;
margin-left: auto;
margin-right: auto;
but this didn't work. It stretches the div when I do this.
Anyone know what to do here?
center an auto-width div?
Started by jimiwa, Jul 29 2010 03:08 PM
4 replies to this topic
#1
Posted 29 July 2010 - 03:08 PM
|
|
|
#2
Posted 29 July 2010 - 04:52 PM
Which way do you want the size to adjust, vertically, horizontally, or both?
sudo rm -rf /
#3
Posted 29 July 2010 - 04:52 PM
This might work. I haven't tested it but in theory it should.
CSS:
HTML:
CSS:
#wrapper{
text-align:center;
}
#content{
width: auto;
display: inline;
text-align:left;
}
HTML:
<div id="wrapper"> <div id="content"> CENTERED DIV </div> </div>
#4
Posted 30 July 2010 - 02:01 PM
InitVI: I tried it, and actually the div stretches the whole page that way, if you put a background color,
you can see that this happens.
dargueta: I want the size to adjust horizontally, but I would like to know how to do it either way.
you can see that this happens.
dargueta: I want the size to adjust horizontally, but I would like to know how to do it either way.
#5
Posted 31 July 2010 - 02:14 PM


Sign In
Create Account


Back to top









