Question:

How block elements can be centered with CSS1?

Answer:

Block level elements can be centered by:

The margin-left and margin-right properties can be set to some explicit value:

BODY {
 
width: 40em;
 
background: fluorescent;
 
}
 
P {
 
width: 30em;
 
margin-right: auto;
 
margin-left: auto
 
}

In this case, the left and right margins will be each, five ems wide since they split up the ten ems left over from (40em-30em). It was unnecessary for setting up an explicit width for the BODY element; it was done here for simplicity.


Keywords:

© 2017 QuizBucket.org