Due to the vertical center problem of div due to 12306 errors, I want to see if there are still no remaining tickets when I go home on New Year's Day. I opened 12306 secretly and started to query the tickets for returning home. I found that I could not query them, an error occurred while checking again.
Seeing this is very depressing and tangled, But I suddenly thought that I had been trying to center p vertically recently. I tried a website as large as 12306 and it must be vertically centered,
After a try, I was not disappointed and adapted to the vertical center of various resolutions.
Great. Right-click the source code.
P class = "err_text">
-
- Network problems may exist. Please try again!
Then let's take a look at how css is written.
.err_text{ position:absolute; margin-top:-159px; top:50%; left:50%; margin-left:-247px; width:495px; height:282px;}#error{ width:495px; margin-left:auto; margin-right:auto; list-style:none;}#error li{ list-style:none;}#err_top{ background:url(err_top.gif) no-repeat; height:78px; line-height:78px; width:495px; }#err_bot{ background:url(err_bot.gif) no-repeat; height:204px; padding-top:50px; width:495px; text-align:center; font-size:14px; font-weight:bold;}
At this time, you will surely find that the key code is actually top: 50%, left: 50%. Of course, the premise is absolute positioning, so that you can center it.