-
SitePoint Enthusiast
Fitting width to contents and centering
I've been breaking my head trying to achieve the following.
I have a div that must "shrink-to-fit" it's contents (a variable size image and some other absolutely positioned divs).
And that div has to also center on the page.
The CSS for the div looks like
#name {
position: relative;
overflow: hidden;
}
I've done float: left to it which shrinks the width to fit the contents but then how do I center it?
I've also tried doing display: inline-table but for some reason it's taking up 100% width.
-
-
SitePoint Enthusiast
Hi there,
It doesn't work since the div is floated on the left in order to trigger shrink-to-fit
-
SitePoint Enthusiast
Still having problems with this.
Does anyone know how to make a div fit to contents width wise and center on page?
-
SitePoint Enthusiast
how bout this:
body {
margin: 0;
text-align: center;
}
#wrap {
background: #000;
display: inline;
}
-
SitePoint Enthusiast
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks