When we reconstruct the WEB now, we usually center the DIV like this:
body{
margin:0px auto;
text-align:center;
}
But when the following parsing method is not declared, the page An error will occur. It cannot be centered and aligned!
Troubled by this It took me a few days. Then some friends will say: Can't you just add this sentence? But sometimes the page cannot be written according to the code format specified above, for example, you need to change the colorful scroll bar.
Until yesterday, an idea flashed in my mind. Why not use JS to control the margins of the page? Just do it!
I found a page. I added the following short piece of code.
function.js content:
if(window.screen.width>800){document.write("");}
Save and test. Haha, I changed a few resolutions All can be centered normally! So far, the test has been successful.
To summarize:
Mainly because of the role of this code:
(window.screen.width-800)/2 //Calculate the margin value that should be left on the page. 800 is my DIV width + scroll bar width. Actual Change the application to your own size.
Additional point: the above JS must be placed after your last CSS connection or .
Welcome everyone to my A better way to implement small station communication!