Is there a way for my main div to have an initial width of 1024px but be able to expand based on the content if the content is longer that 1024px?
Also, the possible contents are dynamic, so if the content is longer than 1024px, then the main div must expand to accommodate the content. But if the content is smaller than 1024, then it should remain as 1024px centered on the screen.
HTML
<div id="main">
<h1>Title</h1>
<div id="otherContent">
<!-- other content here -->
</div>
</div>
CSS
#main {
width: 1024px;
margin: 0 auto;
}
Here is a fiddle with examples (Examples are based on 600px instead of 1024px)
Edit: The main div is also centered using margin.
display: inline-blockon the elements with themin-width? Like this example?inline-blockwill fit the width to the content.inline-tableon the table elements so that they are shrunk down in width. The tables are then centered withtext-align: centeron the parent div. Example for you here