{"id":5294,"date":"2025-03-06T12:22:27","date_gmt":"2025-03-06T12:22:27","guid":{"rendered":"https:\/\/hocoos.com\/?post_type=answer&#038;p=5294"},"modified":"2025-03-06T12:22:28","modified_gmt":"2025-03-06T12:22:28","slug":"what-are-flexible-images","status":"publish","type":"answer","link":"https:\/\/hocoos.com\/zh\/%e7%ad%94%e6%a1%88\/what-are-flexible-images\/","title":{"rendered":"\u4ec0\u4e48\u662f\u5f39\u6027\u56fe\u50cf\uff1f"},"content":{"rendered":"<h2 class=\"wp-block-heading\"><strong>\u5982\u4f55\u4f7f\u7528 CSS \u4f7f\u56fe\u7247\u5177\u6709\u5f39\u6027\uff1f<\/strong><\/h2>\n\n\n\n<p>\u4e3a\u5b9e\u73b0\u56fe\u7247\u7684\u7075\u6d3b\u6027\uff0c\u63d0\u4f9b\u4e86\u4ee5\u4e0bCSS\u89c4\u5219\uff1a<\/p>\n\n\n\n<p>CSS<\/p>\n\n\n\n<p>img {<br>&nbsp; max-width: 100%;<br>&nbsp; height: auto;<br>}<br><\/p>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u6709\u6548\u5730\u6307\u793a\u6d4f\u89c8\u5668\u9632\u6b62\u56fe\u7247\u5c3a\u5bf8\u8d85\u8fc7\u5176\u5bb9\u5668\uff0c\u540c\u65f6\u4fdd\u6301\u5176\u9ad8\u5ea6\uff0c\u4ece\u800c\u4fdd\u7559\u539f\u59cb\u7eb5\u6a2a\u6bd4\u3002<\/p>\n\n\n\n<div class=\"answers-tip-box mt-8 mt-lg-10\">\n<div class=\"answers-small-title\">\n\t\t\t\t\t\t\t\n\u4e13\u5bb6\u63d0\u793a\uff1a\u00a0\n\n<\/div>\n<div class=\"answers-small-description mt-4\">\n\n\u5982\u679c\u60a8\u5e0c\u671b\u56fe\u7247\u5927\u5c0f\u8c03\u6574\u66f4\u7075\u6d3b\uff0c\u53ef\u4ee5\u6dfb\u52a0CSS\u5a92\u4f53\u67e5\u8be2\uff0c\u9488\u5bf9\u7279\u5b9a\u5c4f\u5e55\u5206\u8fa8\u7387\u8c03\u6574\u6837\u5f0f\u8868\u3002\n\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:72px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4ec0\u4e48\u662f srcset \u5c5e\u6027\uff1f\u5b83\u4e0e\u7075\u6d3b\u56fe\u50cf\u6709\u4ec0\u4e48\u5173\u7cfb\uff1f<\/strong><\/h2>\n\n\n\n<p>srcset \u5c5e\u6027\u4f7f\u60a8\u53ef\u4ee5\u6307\u5b9a\u540c\u4e00\u56fe\u50cf\u7684\u591a\u4e2a\u4e0d\u540c\u5206\u8fa8\u7387\u7684\u7248\u672c\uff0c\u4ee5\u4fbf\u6839\u636e\u7528\u6237\u7684\u5c4f\u5e55\u5c3a\u5bf8\u548c\u5206\u8fa8\u7387\u52a0\u8f7d\u6700\u5408\u9002\u7684\u7248\u672c\u3002\u63d0\u4f9b\u6700\u5408\u9002\u7684\u56fe\u50cf\u7248\u672c\u4f1a\u5f71\u54cd\u6027\u80fd\u901f\u5ea6\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n\n\n\n<div class=\"answers-tip-box mt-8 mt-lg-10\">\n<div class=\"answers-small-title\">\n\t\t\t\t\t\t\t\n\u4e13\u5bb6\u63d0\u793a\uff1a\u00a0\n\n<\/div>\n<div class=\"answers-small-description mt-4\">\n\n\u540c\u65f6\u4f7f\u7528srcset\u548csizes\u4fee\u9970\u7b26\uff0c\u53ef\u4ee5\u5411\u6d4f\u89c8\u5668\u4f20\u8fbe\u66f4\u591a\u5173\u4e8e\u6700\u5408\u9002\u56fe\u50cf\u6e90\u7684\u4fe1\u606f\u3002\n\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:72px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4f7f\u7528\u7075\u6d3b\u56fe\u50cf\u6709\u4ec0\u4e48\u597d\u5904\uff1f<\/strong><\/h2>\n\n\n\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7075\u6d3b\u7684\u56fe\u50cf\u53ef\u80fd\u4f1a\u5bfc\u81f4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u56fe\u50cf\u6e32\u67d3\uff1a<\/strong> \u56fe\u50cf\u7ecf\u8fc7\u5904\u7406\uff0c\u4ee5\u5728\u5404\u79cd\u8bbe\u5907\u548c\u5c4f\u5e55\u5206\u8fa8\u7387\u4e0a\u4fdd\u6301\u6e05\u6670\u5ea6\u548c\u53ef\u89c1\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9875\u9762\u4f18\u5316\uff1a<\/strong> \u6d4f\u89c8\u5668\u4f1a\u8c03\u6574\u56fe\u50cf\u5927\u5c0f\uff0c\u4ee5\u6f5c\u5728\u5730\u51cf\u5c11\u6570\u636e\u6d88\u8017\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/hocoos.com\/zh\/%e7%ad%94%e6%a1%88\/%e4%bb%80%e4%b9%88%e6%98%afseo\/\" data-type=\"answer\" data-id=\"4440\">\u63d0\u5347 SEO<\/a>:<\/strong> Google \u66f4\u559c\u6b22 <a href=\"https:\/\/hocoos.com\/zh\/%e7%ad%94%e6%a1%88\/%e4%bb%80%e4%b9%88%e6%98%af%e7%a7%bb%e5%8a%a8%e5%93%8d%e5%ba%94%e5%bc%8f\/\" data-type=\"answer\" data-id=\"3386\">\u9002\u5408\u79fb\u52a8\u8bbe\u5907\u7684\u7f51\u7ad9<\/a>\uff0c\u800c\u7075\u6d3b\u7684\u56fe\u50cf\u662f\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u7684\u57fa\u7840\u4e4b\u4e00\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"answers-tip-box mt-8 mt-lg-10\">\n<div class=\"answers-small-title\">\n\t\t\t\t\t\t\t\n\u4e13\u5bb6\u63d0\u793a\uff1a\u00a0\n\n<\/div>\n<div class=\"answers-small-description mt-4\">\n\n\u8003\u8651\u4f7f\u7528\u73b0\u4ee3\u56fe\u50cf\u683c\u5f0f\uff0c\u5982 WebP \u6216 AVIF\uff0c\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6027\u80fd\uff0c\u56e0\u4e3a\u5b83\u4eec\u6bd4 JPEG \u6216 PNG \u7b49\u4f20\u7edf\u683c\u5f0f\u63d0\u4f9b\u66f4\u597d\u7684\u538b\u7f29\u6548\u679c\u3002\n\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:72px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4f7f\u7528\u7075\u6d3b\u7684\u56fe\u7247\u662f\u5426\u5b58\u5728\u4efb\u4f55\u6f5c\u5728\u7684\u7f3a\u70b9\u6216\u6ce8\u610f\u4e8b\u9879\uff1f<\/strong><\/h2>\n\n\n\n<p>\u5c3d\u7ba1\u54cd\u5e94\u5f0f\u56fe\u50cf\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u662f\u4e00\u79cd\u5f88\u597d\u7684\u505a\u6cd5\uff0c\u4f46\u5fc5\u987b\u8003\u8651\u4e00\u4e9b\u56e0\u7d20\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u590d\u6742\u6027\uff1a<\/strong> \u867d\u7136\u54cd\u5e94\u5f0f\u56fe\u50cf\u5177\u6709\u4f18\u52bf\uff0c\u4f46\u7531\u4e8e srcset \u548c\u6807\u7b7e\uff0c\u5b83\u4eec\u4f1a\u589e\u52a0\u4ee3\u7801\u7684\u590d\u6742\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u827a\u672f\u6307\u5bfc\uff1a<\/strong> \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u56fe\u50cf\u5fc5\u987b\u4ee5\u51e0\u79cd\u4e0d\u540c\u7684\u65b9\u5f0f\u8fdb\u884c\u7f16\u8f91\u5e76\u5b58\u50a8\u4e3a\u5355\u72ec\u7684\u6587\u4ef6\uff0c\u4ee5\u4fbf\u5728\u8c03\u6574\u5927\u5c0f\u65f6\u770b\u8d77\u6765\u4e0d\u9519\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\uff1a<\/strong> \u5c3d\u7ba1\u5927\u591a\u6570\u73b0\u4ee3\u6d4f\u89c8\u5668\u53ef\u4ee5\u5904\u7406\u54cd\u5e94\u5f0f\u56fe\u50cf\uff0c\u4f46\u4e00\u4e9b\u8f83\u65e7\u7684\u6d4f\u89c8\u5668\u65e0\u6cd5\u5904\u7406\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u9700\u8981\u4e3a\u5b83\u4eec\u521b\u5efa\u7f29\u653e\u5668\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u867d\u7136\u54cd\u5e94\u5f0f\u56fe\u50cf\u786e\u5b9e\u6709\u4e00\u4e9b\u6f5c\u5728\u7684\u7f3a\u70b9\uff0c\u4f46\u5176\u4f18\u52bf\u5728\u6574\u4f53\u6743\u8861\u4e2d\u4f3c\u4e4e\u66f4\u4e3a\u91cd\u8981\u3002\u7075\u6d3b\u7684\u56fe\u50cf\u5728\u786e\u4fdd\u5f53\u4ee3\u7f51\u9875\u6613\u4e8e\u6d4f\u89c8\u548c\u4f7f\u7528\u65b9\u9762\u53d1\u6325\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\uff0c\u8fd9\u5bf9\u7528\u6237\u4f53\u9a8c\u81f3\u5173\u91cd\u8981\u3002<\/p>\n\n\n\n<div style=\"height:72px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<p>\u5728\u6211\u4eec\u6240\u5904\u7684\u5f53\u4ee3\u73af\u5883\u4e2d\uff0c\u6bcf\u4e2a\u4eba\u90fd\u901a\u8fc7\u4e0d\u540c\u7684\u8bbe\u5907\u8bbf\u95ee\u4fe1\u606f\uff0c\u54cd\u5e94\u5f0f\u56fe\u50cf\u5df2\u6210\u4e3a\u4e00\u79cd\u666e\u904d\u9700\u6c42\uff0c\u800c\u975e\u5962\u4f88\u54c1\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5728\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8\u4e0b\u83b7\u5f97\u66f4\u4e00\u81f4\u7684\u7528\u6237\u4f53\u9a8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u7b80\u5355\u7684 CSS \u6280\u672f\u548c srcset \u5c5e\u6027\u3002\u8fd9\u4e9b\u6280\u672f\u53ef\u80fd\u4f1a\u6539\u5584\u60a8\u7f51\u7ad9\u5728\u5404\u79cd\u8bbe\u5907\u4e0a\u7684\u89c6\u89c9\u5448\u73b0\u548c\u54cd\u5e94\u901f\u5ea6\uff0c\u4f46\u8bf7\u8bb0\u4f4f\uff0c\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u56e0\u7d20\u4f1a\u5f71\u54cd\u6574\u4f53\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>How do I make images flexible using CSS? A CSS rule is provided for the flexibility of images: CSS img {&nbsp; max-width: 100%;&nbsp; height: auto;} This piece of code effectively instructs the browser to prevent the image from becoming larger than the container from which it is held while also maintaining its height so that [&hellip;]<\/p>","protected":false},"author":39,"featured_media":5295,"template":"","answers_category":[24],"class_list":["post-5294","answer","type-answer","status-publish","has-post-thumbnail","hentry","answers_category-mobile-responsiveness"],"acf":{"image":null,"card_image":5295,"content":[{"acf_fc_layout":"header_section","title":"\u4ec0\u4e48\u662f\u5f39\u6027\u56fe\u50cf\uff1f","descriptions":"Flexible images are designed to adapt their appearance to fit the dimensions of their container, minimizing distortion and overflow across different screen sizes.<br\/><br\/>Considering the prevalence of diverse screen sizes in modern technology, ranging from large desktop monitors to small smartphone screens, this set of features holds importance for websites today.\r\n","tip_label":"","tip":"","additional_tips":null,"key_takeaways_label":"Key Takeaways:","key_takeaways":[{"label":"Images that can fit any aspect ratio are required by modern sites","body":""},{"label":"Use CSS for the flexibility needed","body":""},{"label":"Granular control is provided via the srcset attribute","body":""}]}]},"_links":{"self":[{"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/answer\/5294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/answer"}],"about":[{"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/types\/answer"}],"author":[{"embeddable":true,"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/users\/39"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/media\/5295"}],"wp:attachment":[{"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/media?parent=5294"}],"wp:term":[{"taxonomy":"answers_category","embeddable":true,"href":"https:\/\/hocoos.com\/zh\/wp-json\/wp\/v2\/answers_category?post=5294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}