0

How to center all the HTML elements horizontally and vertically between the <body> </body> without updating the elements left: and top: property when the window gets resised.

Belgacem Ksiksi
  • 244
  • 1
  • 5
  • 18
  • This question is a bit too general: Keep in mind that centering HTML elements does not imply that their *content* again is centered, like text inside a DIV or a DIV inside another DIV etc., as it's the case in most situations. – Johannes Jan 20 '17 at 13:15

1 Answers1

-1

.center { margin: auto auto 3px 3px; }

By using this in your internal or external CSS file all the text elements will be center aligned and there will be a margin of 3 pixels above and below the division.

Rachit
  • 7
  • 1
  • You also need a width declared. Block-level elements have width: 100% by default so just the above won't change anything. Plus the margin shorthand is off. That says "top: auto, right: auto, bottom 3px, left 3px". Update to: .center {width: 960px; margin: 3px auto;} – tjameswhite Jan 20 '17 at 13:08
  • 1
    that's wrong: the order in combined CSS rules is top - right - bottom - left, so this would be auto at top and right and 3px bottom and left. Plus this doesn't do anything if there isn't any position parameter. – Johannes Jan 20 '17 at 13:09