{"id":2862,"date":"2020-04-18T20:55:11","date_gmt":"2020-04-18T12:55:11","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=2862"},"modified":"2020-04-18T21:01:11","modified_gmt":"2020-04-18T13:01:11","slug":"css%e5%b8%83%e5%b1%80%e7%b3%bb%e5%88%97-%e5%b1%85%e4%b8%ad%e7%9b%b8%e5%85%b3%e7%9a%84%e5%b8%83%e5%b1%80","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2862","title":{"rendered":"css\u5e03\u5c40\u7cfb\u5217-\u5c45\u4e2d\u76f8\u5173\u7684\u5e03\u5c40"},"content":{"rendered":"<h2>1. \u5c45\u4e2d\u76f8\u5173\u7684\u5e03\u5c40<\/h2>\n<h3>1.1 \u6c34\u5e73\u5c45\u4e2d\u5e03\u5c40<\/h3>\n<p>\u6548\u679c\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/middle1.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2863\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/middle1.png\" alt=\"middle1\" width=\"728\" height=\"106\" \/><\/a><\/p>\n<h4>\u65b9\u6848\u4e00. <code>inline<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>block<\/code> + <code>text<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align<\/code><\/h4>\n<p>\u5206\u6790\uff1a<code>display<\/code>\u8bbe\u7f6e\u4e3a<code>inline<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>block<\/code>\u7684\u5143\u7d20\uff0c\u5177\u6709\u6587\u672c\u5143\u7d20\u7684\u6027\u8d28\uff0c\u5176\u7236\u5143\u7d20\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u5bf9\u9f50\u5c5e\u6027<code>text<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align<\/code>\u6765\u63a7\u5236\u5176\u5728\u884c\u5185\u7684\u5bf9\u9f50\u65b9\u5f0f\uff0c<code>text<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align: center<\/code>\u5373\u4e3a\u6c34\u5e73\u5bf9\u9f50<\/p>\n<p>\u6ce8\u610f\uff1a<code>text<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align<\/code>\u5c5e\u6027\u662f\u5177\u6709\u7ee7\u627f\u6027\u7684\uff0c\u4f1a\u5bfc\u81f4\u81ea\u5df1\u5143\u7d20\u5185\u90e8\u7684\u6587\u672c\u4e5f\u662f\u5c45\u4e2d\u663e\u793a\u7684\uff0c\u9700\u8981\u81ea\u8eab\u8bbe\u7f6e<code>text<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align<\/code>\u8986\u76d6<\/p>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        width: 100%;\r\n        height: 200px;\r\n        background-color: aqua;\r\n        text-align: center;\r\n    }\r\n    .content {\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n        display: inline-block;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u4e8c. \u5b9a\u4f4d + <code>transform<\/code><\/h4>\n<p>\u5206\u6790\uff1a\u7236\u5143\u7d20\u5f00\u542f\u5b9a\u4f4d\uff08relative\uff0cabsolute,fixed\u90fd\u53ef\u4ee5\uff09\u540e\uff0c\u5b50\u5143\u7d20\u8bbe\u7f6e\u7edd\u5bf9\u5b9a\u4f4d<code>absolute<\/code>\u540e\uff0c<code>left<\/code>\u8bbe\u7f6e\u4e3a<code>50%<\/code>\uff0c\u518d\u4f7f\u7528<code>transform: translateX(<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>50%)<\/code>\u5c06\u5b50\u5143\u7d20\u5f80\u53cd\u65b9\u5411\u79fb\u52a8\u81ea\u8eab\u5bbd\u5ea6\u7684<code>50%<\/code>\uff0c\u4fbf\u5b8c\u6210\u6c34\u5e73\u5c45\u4e2d\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u7236\u7ea7\u5143\u7d20\u662f\u5426\u8131\u79bb\u6587\u6863\u6d41\uff0c\u4e0d\u5f71\u54cd\u5b50\u5143\u7d20\u6c34\u5e73\u5c45\u4e2d\u6548\u679c\uff0c\u4f46\u662f<code>transform<\/code>\u662f<code>css3<\/code>\u5c5e\u6027\uff0c\u5b58\u5728\u6d4f\u89c8\u5668\u517c\u5bb9\u95ee\u9898<\/p>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        position: relative;\r\n        width: 100%;\r\n        height: 200px;\r\n        background-color: aqua;\r\n    }\r\n    .content {\r\n        position: absolute;\r\n        left: 50%;\r\n        transform: translateX(-50%);\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u4e09. <code>display: block<\/code> + <code>margin: 0 auto<\/code><\/h4>\n<p>\u5206\u6790\uff1a \u8fd9\u4e2a\u65b9\u6cd5\u53ea\u9700\u8981\u5bf9\u5b50\u5143\u7d20\u8fdb\u884c\u8bbe\u7f6e\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6c34\u5e73\u5c45\u4e2d\uff0cmargin\u8bbe\u7f6eauto\u8868\u793a\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u5206\u914d\uff0c\u5b9e\u73b0\u6765\u5916\u8fb9\u8ddd\u7b49\u5206\u6548\u679c\u3002<\/p>\n<p>\u6ce8\u610f\uff1a \u8fd9\u91cc\u5b50\u5143\u7d20\u8bbe\u7f6e<code>display<\/code>\u4e3a<code>block<\/code>\u6216\u8005<code>table<\/code>\u90fd\u662f\u53ef\u4ee5\u7684\uff0c\u5982\u679c\u5b50\u5143\u7d20\u8131\u79bb\u6587\u6863\u6d41\uff08\u6d6e\u52a8\uff0c\u5b9a\u4f4d\uff09\uff0c\u4f1a\u5bfc\u81f4margin\u5c5e\u6027\u7684\u503c\u65e0\u6548\u3002<\/p>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        width: 100%;\r\n        height: 200px;\r\n        background-color: aqua;\r\n    }\r\n    .content {\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n        display: table;\r\n        margin: 0 auto;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u56db. flex\u5f39\u6027\u76d2\u5b50\u5e03\u5c40<\/h4>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n\/* flex *\/\r\n.wrap{\r\n    display: flex;\r\n    justify-content: center;\r\n}\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n   &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>1.2 \u5782\u76f4\u5c45\u4e2d\u5e03\u5c40<\/h3>\n<p>\u6548\u679c\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/vertifimiddle.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2864\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/vertifimiddle.png\" alt=\"vertifimiddle\" width=\"177\" height=\"529\" \/><\/a><\/p>\n<h4>\u65b9\u6848\u4e00. \u5b9a\u4f4d + <code>transform<\/code><\/h4>\n<p>\u8fd9\u79cd\u65b9\u6848\u548c\u4e4b\u524d\u6c34\u5e73\u5c45\u4e2d\u5e03\u5c40\u7684\u65b9\u6848\u4e8c\u662f\u540c\u6837\u7684\u539f\u7406\uff0c\u4e0d\u5728\u8d58\u8ff0<\/p>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        position: relative;\r\n        width: 200px;\r\n        height: 600px;\r\n        background-color: aqua;\r\n    }\r\n    .content {\r\n        position: absolute;\r\n        top: 50%;\r\n        transform: translateY(-50%);\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u4e8c. <code>display: table<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>cell<\/code> + <code>vertical<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align<\/code><\/h4>\n<p>\u5206\u6790\uff1a\u8bbe\u7f6e<code>display: table<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>cell<\/code>\u7684\u5143\u7d20\u5177\u6709<code>td<\/code>\u5143\u7d20\u7684\u884c\u4e3a\uff0c\u5b83\u7684\u5b50\u5143\u7d20\u5e03\u5c40\u65b9\u5f0f\u7c7b\u4f3c\u6587\u672c\u5143\u7d20\uff0c\u53ef\u4ee5\u5728\u7236\u5143\u7d20\u4f7f\u7528<code>vertical<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align: middle<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">;<\/span><\/code>\u5b9e\u73b0\u5b50\u5143\u7d20\u7684\u5782\u76f4\u5c45\u4e2d\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<code>vertical<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>align<\/code>\u5c5e\u6027\u5177\u6709\u7ee7\u627f\u6027\uff0c\u5bfc\u81f4\u7236\u5143\u7d20\u5185\u6587\u672c\u4e5f\u662f\u5782\u76f4\u5c45\u4e2d\u663e\u793a\u7684\u3002<\/p>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        display: table-cell;\r\n        vertical-align: middle;\r\n        width: 200px;\r\n        height: 600px;\r\n        background-color: aqua;\r\n    }\r\n    .content {\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u4e09. Flex<\/h4>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n\/* flex *\/\r\n.wrap{\r\n    display: flex;\r\n    \/* flex-direction: column;\r\n    justify-content: center; *\/\r\n    align-items: center;\r\n}\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n     &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u56db. \u56fa\u5b9a\u9ad8\u5ea6=\u884c\u9ad8<\/h4>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n\/* content \u53ef\u4ee5\u662f\u884c\u6216\u5757\u5143\u7d20 *\/\r\n.wrap{\r\n    height:300px;\r\n    line-height: 300px;\r\n}\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n     &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>1.3 \u6c34\u5e73\u5782\u76f4\u5c45\u4e2d\u5e03\u5c40<\/h3>\n<p>\u6548\u679c\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/middle2.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2865\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/middle2.png\" alt=\"middle2\" width=\"566\" height=\"368\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/middle2.png 566w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/middle2-90x60.png 90w\" sizes=\"(max-width: 566px) 100vw, 566px\" \/><\/a><\/p>\n<h4>\u65b9\u6848\u4e00.\u5b9a\u4f4d + <code>transform<\/code><\/h4>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        position: relative;\r\n        width: 1200px;\r\n        height: 800px;\r\n        background-color: aqua;\r\n    }\r\n    .content {\r\n        position: absolute;\r\n        left: 50%;\r\n        top: 50%;\r\n        transform: translate(-50%, -50%);\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h4>\u65b9\u6848\u4e8c. \u7ed3\u5408\u6c34\u5e73\u5e03\u5c40\u65b9\u6848\u4e09\uff0c\u5782\u76f4\u5e03\u5c40\u65b9\u6848\u4e8c<\/h4>\n<pre><code class=\"language-html\" lang=\"html\">&lt;style&gt;\r\n    .wrap {\r\n        display: table-cell;\r\n        vertical-align: middle;\r\n        width: 1200px;\r\n        height: 800px;\r\n        background-color: aqua;\r\n    }\r\n    .content {\r\n        margin: 0 auto;\r\n        width: 200px;\r\n        height: 200px;\r\n        background-color: blueviolet;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;div class=\"wrap\"&gt;\r\n        &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;\r\n\r\n<\/code><\/pre>\n<h3>1.4 \u4f7f\u7528<code>flex<\/code>\u8fdb\u884c\u5c45\u4e2d\u5e03\u5c40<\/h3>\n<p>\u5206\u6790\uff1a\u4f7f\u7528<code>flex<\/code>\uff0c\u6c34\u5e73\u5782\u76f4\u5c45\u4e2d\u4f1a\u53d8\u5f97\u975e\u5e38\u5bb9\u6613\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<code>align<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>items: center<\/code>\u5782\u76f4\u5c45\u4e2d\uff08\u4ea4\u53c9\u8f74\u6392\u5217\u65b9\u5f0f\uff09\uff0c<code>justify<span style=\"font-family: 'Open Sans', 'Clear Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;\">-<\/span>content: center<\/code>\u6c34\u5e73\u5c45\u4e2d\uff08\u4e3b\u8f74\u6392\u5217\u65b9\u5f0f\uff09 \u6ce8\u610f\uff1a \u9700\u8981\u8003\u8651\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n<pre><code class=\"language-html\" lang=\"html\"> &lt;style&gt;\r\n     .wrap {\r\n         display: flex;\r\n         align-items: center;\r\n         justify-content: center;\r\n         width: 1200px;\r\n         height: 800px;\r\n         background-color: aqua;\r\n     }\r\n     .content {\r\n         width: 200px;\r\n         height: 200px;\r\n         background-color: blueviolet;\r\n     }\r\n &lt;\/style&gt;\r\n &lt;body&gt;\r\n     &lt;div class=\"wrap\"&gt;\r\n         &lt;div class=\"content\"&gt;&lt;\/div&gt;\r\n     &lt;\/div&gt;\r\n &lt;\/body&gt;\r\n<\/code><\/pre>\n<p>\u539f\u6587:https:\/\/juejin.im\/post\/5e91a8a56fb9a03c9037928f#heading-12<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5c45\u4e2d\u76f8\u5173\u7684\u5e03\u5c40 1.1 \u6c34\u5e73\u5c45\u4e2d\u5e03\u5c40 \u6548\u679c\u56fe\u5982\u4e0b\uff1a \u65b9\u6848\u4e00. inline-block + text-a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[109,105],"tags":[134],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2862"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2862"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2862\/revisions"}],"predecessor-version":[{"id":2867,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2862\/revisions\/2867"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}