margin: auto - but only up to a point

T

Tim Streater

I have an element that I would like to be centred on the page, so I use:

margin-left: auto;
margin-right: auto;

This is fine but under some conditions the element then expands to fill
the whole width of the window (variable content).

I would like to restrict its expansion to within (say) a few pixels of
the sides of the window. Can I do this with CSS?

Thanks,
 
J

Jonathan N. Little

Tim said:
I have an element that I would like to be centred on the page, so I use:

margin-left: auto;
margin-right: auto;

This is fine but under some conditions the element then expands to fill
the whole width of the window (variable content).

I would like to restrict its expansion to within (say) a few pixels of
the sides of the window. Can I do this with CSS?

width: 99%;
 
T

Tim Streater

"Jonathan N. Little said:
width: 99%;

This appears to *force* the element (a table) to occupy 99% of the
width. I want to *limit* it to that.

I have:

table.outerbox
{
margin-left: auto;
margin-right: auto;
margin-top: 20px;
border-width: 4px;
border-color: black;
border-style: solid;
}


and then:

<table class="outerbox">
rows, cols
</table>

Thx - tim
 
E

Els

Tim said:
This appears to *force* the element (a table) to occupy 99% of the
width. I want to *limit* it to that.

max-width:99%;

(does not work in IE6)
I have:

table.outerbox
{
margin-left: auto;
margin-right: auto;
margin-top: 20px;
border-width: 4px;
border-color: black;
border-style: solid;
}

and then:

<table class="outerbox">
rows, cols
</table>

You could always wrap it inside a div, and give the div a left and
right padding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top