Centering div

  • Thread starter =?ISO-8859-1?Q?=22H=2E_M=E4ki=22?=
  • Start date
?

=?ISO-8859-1?Q?=22H=2E_M=E4ki=22?=

Can I center div-tag somehow if I want to define div width in pixels?

If I define left, right and width in percents it works, but then I can't
define minimum width? (what "min-width" does anyway?)
 
D

David Dorward

H. Mäki said:
Can I center div-tag somehow if I want to define div width in pixels?
http://dorward.me.uk/www/centre/

If I define left, right and width in percents it works, but then I can't
define minimum width? (what "min-width" does anyway?)

Min-width, which is not supported by IE, defines a minimum width and takes
priority over the width property. For example:

width: 20em;
min-width: 150px;

Would create an element 20em wide, unless the font was small enough that
20em was less than 150px, in which case it would be 150px instead.
 
C

cwdjrxyz

H. Mäki said:
Can I center div-tag somehow if I want to define div width in pixels?

If I define left, right and width in percents it works, but then I can't
define minimum width? (what "min-width" does anyway?)

This likely can be done if you do not mind using javascript, but be
aware that a small number of browsers have script turned off. I will
outline what is involved below. In case you are interested, I likely
can find one of my pages that uses it.

Script can be written to detect the screen width.Then the division is
written using a document.write which uses absolute positioning for the
division and the detected screen width. The needed absolute left
position for the division is calculated using script by division of the
detected screen width by 2 to detect the screen width center, and then
by subtraction of 1/2 of the desired division width.
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top