I try to make the body of 1024x768 always remain in the center of the page (top bottom with the same interval, left-right), but I am having problems with this.
I used the trick from the top at 50%, then I put the (absolutely) body at -384px, which is half 768.
However, this method gives me a problem: if your window is less than 768 pixels, you get a scroll bar, but the part of the upper body is cropped, without being able to scroll up (I can still scroll down).
How to solve it?
Edit 1: Here is the code:
HTML code that can be printed on a simple html web page:
<!DOCTYPE html> <html lang="en"> <head> <title>Test</title> <style> html { background-color: blue; } body { background-color: red; font-family: TradeGothic, sans-serif; margin-left: -512px; margin-top: -384px; position: absolute; height: 768px; width: 1024px; left: 50%; top: 50%; } </style> </head> <body> some text </body> </html>
source share