{"id":996,"date":"2016-12-05T14:21:55","date_gmt":"2016-12-05T06:21:55","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=996"},"modified":"2016-12-05T14:21:55","modified_gmt":"2016-12-05T06:21:55","slug":"div-css-%e8%ae%a9%e5%85%83%e7%b4%a0%e5%9e%82%e7%9b%b4%e6%b0%b4%e5%b9%b3%e5%b1%85%e4%b8%ad%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=996","title":{"rendered":"DIV + CSS \u8ba9\u5143\u7d20\u5782\u76f4\u6c34\u5e73\u5c45\u4e2d\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\n\t\u5728\u8bf4\u5230\u8fd9\u4e2a\u95ee\u9898\u7684\u65f6\u5019\uff0c\u4e5f\u8bb8\u6709\u4eba\u4f1a\u95eeCSS\u4e2d\u4e0d\u662f\u6709vertical-align\u5c5e\u6027\u6765\u8bbe\u7f6e\u5782\u76f4\u5c45\u4e2d\u7684\u5417\uff1f\u5373\u4f7f\u662f\u67d0\u4e9b\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u6211\u53ea\u9700\u505a\u5c11\u8bb8\u7684CSS Hack\u6280\u672f\u5c31\u53ef\u4ee5\u554a\uff01\u6240\u4ee5\u5728\u8fd9\u91cc\u6211\u8fd8\u8981\u5570\u55e6\u4e24\u53e5\uff0cCSS\u4e2d\u7684\u786e\u662f\u6709vertical-align\u5c5e\u6027\uff0c\u4f46\u662f\u5b83\u53ea\u5bf9(X)HTML\u5143\u7d20\u4e2d\u62e5\u6709valign\u7279\u6027\u7684\u5143\u7d20\u624d\u751f\u6548\uff0c\u4f8b\u5982\u8868\u683c\u5143\u7d20\u4e2d\u7684&lt;td&gt;\u3001&lt;th&gt;\u3001&lt;caption&gt;\u7b49\uff0c\u800c\u50cf&lt;div&gt;\u3001&lt;span&gt;\u8fd9\u6837\u7684\u5143\u7d20\u662f\u6ca1\u6709valign\u7279\u6027\u7684\uff0c\u56e0\u6b64\u4f7f\u7528vertical-align\u5bf9\u5b83\u4eec\u4e0d\u8d77\u4f5c\u7528\u3002\n<\/p>\n<h2>\n\t\u7edd\u5bf9\u5b9a\u4f4d<br \/>\n<\/h2>\n<pre class=\"brush:css;\">\r\ndiv.box{\r\n\tweight:200px;\r\n\theight:400px;\r\n\t\/\/\u628a\u5143\u7d20\u53d8\u6210\u5b9a\u4f4d\u5143\u7d20\r\n\tposition:absolute;\r\n\t\/\/\u8bbe\u7f6e\u5143\u7d20\u7684\u5b9a\u4f4d\u4f4d\u7f6e\uff0c\u8ddd\u79bb\u4e0a\u3001\u5de6\u90fd\u4e3a50%\r\n\tleft:50%;\r\n\ttop:50%;\r\n\t\/\/\u8bbe\u7f6e\u5143\u7d20\u7684\u5de6\u5916\u8fb9\u8ddd\u3001\u4e0a\u5916\u8fb9\u8ddd\u4e3a\u5bbd\u9ad8\u7684\u8d1f1\/2\r\n\tmargin-left:-100px;\r\n\tmargin-top:-200px;\r\n}<\/pre>\n<p>\n\t<span style=\"color:#4B0082\"><strong>*\u517c\u5bb9\u6027\u597d;\u7f3a\u70b9:\u5fc5\u987b\u77e5\u9053\u5143\u7d20\u7684\u5bbd\u9ad8<\/strong><\/span>\n<\/p>\n<h2>\n\ttransform&nbsp;\u504f\u79fb<br \/>\n<\/h2>\n<pre class=\"brush:css;\">\r\ndiv.box{\r\n\tweight:200px;\r\n\theight:400px;\r\n\t\/\/\u628a\u5143\u7d20\u53d8\u6210\u5b9a\u4f4d\u5143\u7d20\r\n\tposition:absolute;\r\n\t\/\/\u8bbe\u7f6e\u5143\u7d20\u7684\u5b9a\u4f4d\u4f4d\u7f6e\uff0c\u8ddd\u79bb\u4e0a\u3001\u5de6\u90fd\u4e3a50%\r\n\tleft:50%;\r\n\ttop:50%;\r\n\t\/\/\u8bbe\u7f6e\u5143\u7d20\u7684\u76f8\u5bf9\u4e8e\u81ea\u8eab\u7684\u504f\u79fb\u5ea6\u4e3a\u8d1f50%(\u4e5f\u5c31\u662f\u5143\u7d20\u81ea\u8eab\u5c3a\u5bf8\u7684\u4e00\u534a)\r\n\ttransform:translate(-50%,-50%);\r\n}<\/pre>\n<p>\n\t<span style=\"color:#800080\"><strong>*\u8fd9\u662fcss3\u91cc\u7684\u6837\u5f0f;\u7f3a\u70b9:\u517c\u5bb9\u6027\u4e0d\u597d\uff0c\u53ea\u652f\u6301IE9+\u7684\u6d4f\u89c8\u5668<\/strong><\/span>\n<\/p>\n<h2>\n\tmargin:auto<br \/>\n<\/h2>\n<pre class=\"brush:css;\">\r\ndiv.box{\r\n\tweight:200px;\r\n\theight:400px;\r\n\t\/\/\u628a\u5143\u7d20\u53d8\u6210\u5b9a\u4f4d\u5143\u7d20\r\n\tposition:absolute;\r\n\t\/\/\u8bbe\u7f6e\u5143\u7d20\u7684\u5b9a\u4f4d\u4f4d\u7f6e\uff0c\u8ddd\u79bb\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u90fd\u4e3a0\r\n\tleft:0;\r\n\tright:0;\r\n\ttop:0;\r\n\tbottom:0;\r\n\t\/\/\u8bbe\u7f6e\u5143\u7d20\u7684margin\u6837\u5f0f\u503c\u4e3a auto\r\n\tmargin:auto;\r\n}<\/pre>\n<p>\n\t<span style=\"color:#800080\"><strong>*\u517c\u5bb9\u6027\u8f83\u597d\uff0c\u7f3a\u70b9:\u4e0d\u652f\u6301IE7\u4ee5\u4e0b\u7684\u6d4f\u89c8\u5668<\/strong><\/span>\n<\/p>\n<h2>\n\tAbsolute Centering<br \/>\n<\/h2>\n<p>\n\t\u6211\u4eec\u7ecf\u5e38\u7528margin:0 auto\u6765\u5b9e\u73b0\u6c34\u5e73\u5c45\u4e2d\uff0c\u800c\u4e00\u76f4\u8ba4\u4e3amargin:auto\u4e0d\u80fd\u5b9e\u73b0\u5782\u76f4\u5c45\u4e2d&hellip;&hellip;\u5b9e\u9645\u4e0a\uff0c\u5b9e\u73b0\u5782\u76f4\u5c45\u4e2d\u4ec5\u9700\u8981\u58f0\u660e\u5143\u7d20\u9ad8\u5ea6\u548c\u4e0b\u9762\u7684CSS\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center {\r\n  margin: auto;\r\n  position: absolute;\r\n  top: 0; left: 0; bottom: 0; right: 0;\r\n}<\/pre>\n<p>\n\t\u6211\u4e0d\u662f\u8fd9\u79cd\u5b9e\u73b0\u65b9\u6cd5\u7684\u7b2c\u4e00\u4eba\uff0c\u53ef\u80fd\u8fd9\u53ea\u662f\u975e\u5e38\u5e38\u89c1\u7684\u4e00\u79cd\u5c0f\u6280\u672f\uff0c\u6211\u6597\u80c6\u5c06\u5176\u547d\u540d\u4e3a\u7edd\u5bf9\u5c45\u4e2d(Absolute Centering)\uff0c\u867d\u7136\u5982\u6b64\uff0c\u4f46\u662f\u5927\u591a\u6570\u8ba8\u8bba\u5782\u76f4\u5c45\u4e2d\u7684\u6587\u7ae0\u5374\u4ece\u6765\u4e0d\u63d0\u8fd9\u79cd\u65b9\u6cd5\uff0c\u76f4\u5230\u6211\u6700\u8fd1\u6d4f\u89c8\u300a<a href=\"http:\/\/designshack.net\/articles\/css\/how-to-center-anything-with-css\" target=\"_blank\">How to Center Anything WithCSS<\/a>\u300b\u8fd9\u7bc7\u6587\u7ae0\u7684\u8bc4\u8bba\u65f6\u5019\u624d\u53d1\u73b0\u8fd9\u79cd\u7528\u6cd5\u3002\u5728\u8bc4\u8bba\u5217\u8868\u4e2dSimon\u548cPriit\u90fd\u63d0\u53ca\u4e86\u6b64\u65b9\u6cd5\u3002\n<\/p>\n<h2>\n\t\u5bb9\u5668\u5185\uff08Within Container\uff09<br \/>\n<\/h2>\n<p>\n\t\u5185\u5bb9\u5757\u7684\u7236\u5bb9\u5668\u8bbe\u7f6e\u4e3aposition:relative\uff0c\u4f7f\u7528\u4e0a\u8ff0\u7edd\u5bf9\u5c45\u4e2d\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u5185\u5bb9\u5c45\u4e2d\u663e\u793a\u4e8e\u7236\u5bb9\u5668\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Center-Container {\r\n\tposition: relative;\r\n}\r\n.Absolute-Center {\r\n\twidth: 50%;\r\n\theight: 50%;\r\n\toverflow: auto;\r\n\tmargin: auto;\r\n\tposition: absolute;\r\n\ttop: 0; left: 0; bottom: 0; right: 0;\r\n} <\/pre>\n<h2>\n\t\u89c6\u533a\u5185\uff08Within Viewport\uff09<br \/>\n<\/h2>\n<p>\n\t\u60f3\u8ba9\u5185\u5bb9\u5757\u4e00\u76f4\u505c\u7559\u5728\u53ef\u89c6\u533a\u57df\u5185\uff1f\u5c06\u5185\u5bb9\u5757\u8bbe\u7f6e\u4e3aposition:fixed;\u5e76\u8bbe\u7f6e\u4e00\u4e2a\u8f83\u5927\u7684z-index\u5c42\u53e0\u5c5e\u6027\u503c\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center.is-Fixed {\r\n\tposition: fixed;\r\n\tz-index: 999;\r\n}<\/pre>\n<h2>\n\t\u8fb9\u680f (Offsets)<br \/>\n<\/h2>\n<p>\n\t\u5982\u679c\u4f60\u8981\u8bbe\u7f6e\u4e00\u4e2a\u56fa\u9876\u7684\u5934\u6216\u589e\u52a0\u5176\u4ed6\u7684\u8fb9\u680f\uff0c\u53ea\u9700\u8981\u5728\u5185\u5bb9\u5757\u7684\u6837\u5f0f\u4e2d\u52a0\u5165\u50cf\u8fd9\u6837\u7684CSS\u6837\u5f0f\u4ee3\u7801\uff1atop:70px;bottom:auto;\u7531\u4e8e\u5df2\u7ecf\u58f0\u660e\u4e86margin:auto;\uff0c\u8be5\u5185\u5bb9\u5757\u5c06\u4f1a\u5782\u76f4\u5c45\u4e2d\u4e8e\u4f60\u901a\u8fc7top,left,bottom\u548cright\u5c5e\u6027\u5b9a\u4e49\u7684\u8fb9\u754c\u6846\u5185\u3002<br \/>\n\t\u4f60\u53ef\u4ee5\u5c06\u5185\u5bb9\u5757\u56fa\u5b9a\u4e0e\u5c4f\u5e55\u7684\u5de6\u4fa7\u6216\u53f3\u4fa7\uff0c\u5e76\u4e14\u4fdd\u6301\u5185\u5bb9\u5757\u5782\u76f4\u5c45\u4e2d\u3002\u4f7f\u7528right:0;left:auto;\u56fa\u5b9a\u4e8e\u5c4f\u5e55\u53f3\u4fa7\uff0c\u4f7f\u7528left:0;right:auto;\u56fa\u5b9a\u4e0e\u5c4f\u5e55\u5de6\u4fa7\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center.is-Right {\r\n\tleft: auto; right: 20px;\r\n\ttext-align: right;\r\n}\r\n.Absolute-Center.is-Left {\r\n\tright: auto; left: 20px;\r\n\ttext-align: left;\r\n} <\/pre>\n<h2>\n\t\u54cd\u5e94\u5f0f\/\u81ea\u9002\u5e94(Responsive)<br \/>\n<\/h2>\n<p>\n\t\u7edd\u5bf9\u5c45\u4e2d\u6700\u5927\u7684\u4f18\u52bf\u5e94\u8be5\u5c31\u662f\u5bf9\u767e\u5206\u6bd4\u5f62\u5f0f\u7684\u5bbd\u9ad8\u652f\u6301\u7684\u975e\u5e38\u5b8c\u7f8e\u3002\u751a\u81f3min-width\/max-width \u548cmin-height\/max-height\u8fd9\u4e9b\u5c5e\u6027\u5728\u81ea\u9002\u5e94\u76d2\u5b50\u5185\u7684\u8868\u73b0\u4e5f\u548c\u9884\u671f\u5f88\u4e00\u81f4\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center.is-Responsive {\r\n\twidth: 60%; \r\n\theight: 60%;\r\n\tmin-width: 200px;\r\n\tmax-width: 400px;\r\n\tpadding: 40px;\r\n}<\/pre>\n<h2>\n\t\u6ea2\u51fa\u60c5\u51b5(Overflow)<br \/>\n<\/h2>\n<p>\n\t\u5185\u5bb9\u9ad8\u5ea6\u5927\u4e8e\u5757\u5143\u7d20\u6216\u5bb9\u5668\uff08\u89c6\u533aviewport\u6216\u8bbe\u4e3aposition:relative\u7684\u7236\u5bb9\u5668\uff09\u4f1a\u6ea2\u51fa\uff0c\u8fd9\u65f6\u5185\u5bb9\u53ef\u80fd\u4f1a\u663e\u793a\u5230\u5757\u4e0e\u5bb9\u5668\u7684\u5916\u9762\uff0c\u6216\u8005\u88ab\u622a\u65ad\u51fa\u73b0\u663e\u793a\u4e0d\u5168\uff08\u5206\u522b\u5bf9\u5e94\u5185\u5bb9\u5757overflow\u5c5e\u6027\u8bbe\u7f6e\u4e3avisible\u548chidden\u7684\u8868\u73b0\uff09\u3002<br \/>\n\t\u52a0\u4e0aoverflow: auto\u4f1a\u5728\u5185\u5bb9\u9ad8\u5ea6\u8d85\u8fc7\u5bb9\u5668\u9ad8\u5ea6\u7684\u60c5\u51b5\u4e0b\u7ed9\u5185\u5bb9\u5757\u663e\u793a\u6eda\u52a8\u6761\u800c\u4e0d\u8d8a\u754c\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center.-Overflow {  \r\n\toverflow: auto;  \r\n} <\/pre>\n<p>\n\t\u5982\u679c\u5185\u5bb9\u5757\u81ea\u8eab\u4e0d\u8bbe\u7f6e\u4efb\u4f55padding\u7684\u8bdd\uff0c\u53ef\u4ee5\u8bbe\u7f6emax-height: 100%;\u6765\u4fdd\u8bc1\u5185\u5bb9\u9ad8\u5ea6\u4e0d\u8d85\u8d8a\u5bb9\u5668\u9ad8\u5ea6\u3002\n<\/p>\n<h2>\n\t\u91cd\u7ed8(Resizing)<br \/>\n<\/h2>\n<p>\n\t\u4f60\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6class\u7c7b\u6216javascript\u4ee3\u7801\u6765\u91cd\u7ed8\u5185\u5bb9\u5757\u540c\u65f6\u4fdd\u8bc1\u5c45\u4e2d\uff0c\u65e0\u987b\u624b\u52a8\u91cd\u65b0\u8ba1\u7b97\u4e2d\u5fc3\u5c3a\u5bf8\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u6dfb\u52a0resize\u5c5e\u6027\u6765\u8ba9\u7528\u6237\u62d6\u62fd\u5b9e\u73b0\u5185\u5bb9\u5757\u7684\u91cd\u7ed8\u3002<br \/>\n\t\u7edd\u5bf9\u5c45\u4e2d\uff08Absolute Centering\uff09\u53ef\u4ee5\u4fdd\u8bc1\u5185\u5bb9\u5757\u59cb\u7ec8\u5c45\u4e2d\uff0c\u65e0\u8bba\u5185\u5bb9\u5757\u662f\u5426\u91cd\u7ed8\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6emin-\/max-\u6765\u6839\u636e\u81ea\u5df1\u9700\u8981\u9650\u5236\u5185\u5bb9\u5757\u7684\u5927\u5c0f\uff0c\u5e76\u9632\u6b62\u5185\u5bb9\u6ea2\u51fa\u7a97\u53e3\/\u5bb9\u5668\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center.is-Resizable {  \r\n  min-width: 20%;  \r\n  max-width: 80%;  \r\n  min-height: 20%;  \r\n  max-height: 80%;  \r\n  resize: both;  \r\n  overflow: auto;  \r\n} <\/pre>\n<p>\n\t\u5982\u679c\u4e0d\u4f7f\u7528resize:both\u5c5e\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528CSS3\u52a8\u753b\u5c5e\u6027transition\u6765\u5b9e\u73b0\u91cd\u7ed8\u7684\u7a97\u53e3\u4e4b\u95f4\u5e73\u6ed1\u7684\u8fc7\u6e21\u3002\u4e00\u5b9a\u8981\u8bbe\u7f6eoverflow:auto;\u4ee5\u9632\u91cd\u7ed8\u7684\u5185\u5bb9\u5757\u5c3a\u5bf8\u5c0f\u4e8e\u5185\u5bb9\u7684\u5b9e\u9645\u5c3a\u5bf8\u8fd9\u79cd\u60c5\u51b5\u51fa\u73b0\u3002<br \/>\n\t\u7edd\u5bf9\u5c45\u4e2d\uff08AbsoluteCentering\uff09\u662f\u552f\u4e00\u652f\u6301resize:both\u5c5e\u6027\u5b9e\u73b0\u5782\u76f4\u5c45\u4e2d\u7684\u6280\u672f\u3002<br \/>\n\t\u6ce8\u610f\uff1a<br \/>\n\t<span style=\"color:#800080\"><strong>\u8981\u8bbe\u7f6emax-width\/max-height\u5c5e\u6027\u6765\u5f25\u8865\u5185\u5bb9\u5757padding\uff0c\u5426\u5219\u53ef\u80fd\u6ea2\u51fa\u3002<br \/>\n\t\u624b\u673a\u6d4f\u89c8\u5668\u548cIE8-IE10\u6d4f\u89c8\u5668\u4e0d\u652f\u6301resize\u5c5e\u6027\uff0c\u6240\u4ee5\u5982\u679c\u5bf9\u4f60\u6765\u8bf4\uff0c\u8fd9\u90e8\u5206\u7528\u6237\u4f53\u9a8c\u5f88\u5fc5\u8981\uff0c\u52a1\u5fc5\u4fdd\u8bc1\u5bf9resizing\u4f60\u7684\u7528\u6237\u6709\u53ef\u884c\u7684\u9000\u8def\u3002<br \/>\n\t\u8054\u5408\u4f7f\u7528resize \u548c transition\u5c5e\u6027\u4f1a\u5728\u7528\u6237\u91cd\u7ed8\u65f6\uff0c\u4ea7\u751f\u4e00\u4e2atransition\u52a8\u753b\u5ef6\u8fdf\u65f6\u95f4\u3002<\/strong><\/span>\n<\/p>\n<h2>\n\t\u56fe\u7247(Images)<br \/>\n<\/h2>\n<p>\n\t\u7edd\u5bf9\u5c45\u4e2d\uff08AbsoluteCentering\uff09\u4e5f\u9002\u7528\u4e8e\u56fe\u7247\u3002\u5bf9\u56fe\u7247\u81ea\u8eab\u5e94\u7528class\u7c7b\u6216CSS\u6837\u5f0f\uff0c\u5e76\u7ed9\u56fe\u7247\u6dfb\u52a0height:auto\u6837\u5f0f\uff0c\u56fe\u7247\u4f1a\u81ea\u9002\u5e94\u5c45\u4e2d\u663e\u793a\uff0c\u5982\u679c\u5916\u5c42\u5bb9\u5668\u53ef\u4ee5resize\u5219\u968f\u7740\u5bb9\u5668\u7684\u91cd\u7ed8\uff0c\u56fe\u7247\u4e5f\u76f8\u5e94\u91cd\u7ed8\uff0c\u59cb\u7ec8\u4fdd\u6301\u5c45\u4e2d\u3002<br \/>\n\t\u9700\u8981\u6ce8\u610f\u7684\u662fheight:auto\u867d\u7136\u5bf9\u56fe\u7247\u5c45\u4e2d\u6709\u7528\uff0c\u4f46\u5982\u679c\u662f\u5728\u56fe\u7247\u5916\u5c42\u7684\u5185\u5bb9\u5757\u4e0a\u5e94\u7528\u4e86height:auto\u5219\u4f1a\u4ea7\u751f\u4e00\u4e9b\u95ee\u9898\uff1a\u89c4\u5219\u7684\u5185\u5bb9\u5757\u4f1a\u88ab\u62c9\u4f38\u586b\u5145\u6574\u4e2a\u5bb9\u5668\u3002\u8fd9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u53ef\u53d8\u9ad8\u5ea6(Variable Height)\u65b9\u5f0f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u95ee\u9898\u7684\u539f\u56e0\u53ef\u80fd\u662f\u6e32\u67d3\u56fe\u7247\u65f6\u8981\u8ba1\u7b97\u56fe\u7247\u9ad8\u5ea6\uff0c\u8fd9\u5c31\u5982\u540c\u4f60\u81ea\u5df1\u5b9a\u4e49\u4e86\u56fe\u7247\u9ad8\u5ea6\u4e00\u6837\uff0c\u6d4f\u89c8\u5668\u5f97\u5230\u4e86\u56fe\u7247\u9ad8\u5ea6\u5c31\u4e0d\u4f1a\u50cf\u5176\u4ed6\u60c5\u51b5\u4e00\u6837\u53bb\u89e3\u6790margin:auto\u5782\u76f4\u5c45\u4e2d\u4e86\u3002\u6240\u4ee5\u6211\u4eec\u6700\u597d\u5bf9\u56fe\u7247\u81ea\u8eab\u5e94\u7528\u8fd9\u4e9b\u6837\u5f0f\u800c\u4e0d\u662f\u7236\u5143\u7d20\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.Absolute-Center.is-Image {  \r\n  height: auto;  \r\n}  \r\n.Absolute-Center.is-Image img {   \r\n  width: 100%;  \r\n  height: auto;  \r\n}  <\/pre>\n<h2>\n\t\u53ef\u53d8\u9ad8\u5ea6\uff08Variable Height\uff09<br \/>\n<\/h2>\n<p>\n\t\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5b9e\u73b0\u7edd\u5bf9\u5c45\u4e2d\uff08AbsoluteCentering\uff09\u5fc5\u987b\u8981\u58f0\u660e\u4e00\u4e2a\u9ad8\u5ea6\uff0c\u4e0d\u7ba1\u4f60\u662f\u57fa\u4e8e\u767e\u5206\u6bd4\u7684\u9ad8\u5ea6\u8fd8\u662f\u901a\u8fc7max-height\u63a7\u5236\u7684\u9ad8\u5ea6\uff0c\u8fd8\u6709\uff0c\u522b\u5fd8\u4e86\u8bbe\u7f6e\u5408\u9002\u7684overflow\u5c5e\u6027\u3002\u5bf9\u81ea\u9002\u5e94\/\u54cd\u5e94\u5f0f\u60c5\u666f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u5f88\u4e0d\u9519\u3002<br \/>\n\t\u4e0e\u58f0\u660e\u9ad8\u5ea6\u6548\u679c\u76f8\u540c\u7684\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u8bbe\u7f6edisplay:table;\u8fd9\u6837\u65e0\u8bba\u5b9e\u9645\u5185\u5bb9\u6709\u591a\u9ad8\uff0c\u5185\u5bb9\u5757\u90fd\u4f1a\u4fdd\u6301\u5c45\u4e2d\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u4e00\u4e9b\u6d4f\u89c8\u5668\uff08\u5982IE\/FireFox\uff09\u4e0a\u4f1a\u6709\u95ee\u9898\uff0c\u6211\u7684\u642d\u6863Kalley&nbsp;<br \/>\n\t\u5728 ELL Creative\uff08\u8bbf\u95eeellcreative.com \uff09\u4e0a\u5199\u4e86\u4e00\u4e2a\u57fa\u4e8eModernizr\u63d2\u4ef6\u7684\u68c0\u6d4b\u51fd\u6570\uff0c\u7528\u6765\u68c0\u6d4b\u6d4f\u89c8\u5668\u662f\u5426\u652f\u6301\u8fd9\u79cd\u5c45\u4e2d\u65b9\u6cd5\uff0c\u8fdb\u4e00\u6b65\u589e\u5f3a\u7528\u6237\u4f53\u9a8c\u3002\n<\/p>\n<pre class=\"brush:css;\">\r\n.absolutecentercontent .Absolute-Center.is-Variable {  \r\n  display: table;  \r\n  height: auto;  \r\n} <\/pre>\n<pre class=\"brush:jscript;\">\r\nModernizr.testStyles(&#039;#modernizr { display: table; height: 50px; width: 50px; margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; }&#039;, function(elem, rule) {  \r\n  Modernizr.addTest(&#039;absolutecentercontent&#039;, Math.round(window.innerHeight \/ 2 - 25) === elem.offsetTop);  \r\n});  \r\n<\/pre>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=996\">DIV + CSS \u8ba9\u5143\u7d20\u5782\u76f4\u6c34\u5e73\u5c45\u4e2d\u7684\u65b9\u6cd5<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728\u8bf4\u5230\u8fd9\u4e2a\u95ee\u9898\u7684\u65f6\u5019\uff0c\u4e5f\u8bb8\u6709\u4eba\u4f1a\u95eeCSS\u4e2d\u4e0d\u662f\u6709vertical-align\u5c5e\u6027\u6765\u8bbe\u7f6e\u5782\u76f4\u5c45\u4e2d\u7684\u5417\uff1f\u5373\u4f7f\u662f\u67d0\u4e9b [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[48,700,701,703,702],"class_list":["post-996","post","type-post","status-publish","format-standard","hentry","category-html5","tag-web","tag-700","tag-701","tag-703","tag-702"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=996"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/996\/revisions"}],"predecessor-version":[{"id":997,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/996\/revisions\/997"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}