{"id":2351,"date":"2023-11-14T15:10:41","date_gmt":"2023-11-14T03:59:45","guid":{"rendered":""},"modified":"2023-11-14T11:59:45","modified_gmt":"2023-11-14T03:59:45","slug":"CSS background-size","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/2351.html","title":{"rendered":"CSS background-size"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

CSS background-size<\/h1>\n<\/p><\/div>\n
\n CSS
\n background-size <\/strong>\u5c5e\u6027\u7528\u4e8e\u8bbe\u7f6e\u5143\u7d20\u7684\u80cc\u666f\u56fe\u50cf\u7684\u5927\u5c0f\u3002\u53ef\u4ee5\u62c9\u4f38\u6216\u9650\u5236\u80cc\u666f\u56fe\u50cf\u4ee5\u9002\u5408\u73b0\u6709\u7a7a\u95f4\u3002\u5b83\u5141\u8bb8\u6211\u4eec\u63a7\u5236\u80cc\u666f\u56fe\u50cf\u7684\u7f29\u653e\u3002\n <\/div>\n
\n \u53ef\u4ee5\u4f7f\u7528
\n \u767e\u5206\u6bd4<\/strong>\u6216
\n \u5173\u952e\u5b57<\/strong>\u503c\u5b9a\u4e49\u6b64\u5c5e\u6027\u3002\u5b83\u6709\u4e24\u4e2a\u53ef\u80fd\u7684\u5173\u952e\u5b57\u503c\uff0c\u5206\u522b\u4e3a
\n contain<\/strong>\u548c
\n cover <\/strong>\u3002\u5b83\u7684\u5355\u503c\u8bed\u6cd5\u5b9a\u4e49\u4e86\u56fe\u50cf\u7684\u5bbd\u5ea6\uff08\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9ad8\u5ea6\u8bbe\u7f6e\u4e3aauto\uff09\uff0c\u800c\u53cc\u7cbe\u5ea6\u503c\u5b9a\u4e49\u4e86height\u548cwidth\u7684\u503c\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u503c\u8bbe\u7f6e\u5bbd\u5ea6\uff0c\u7b2c\u4e8c\u4e2a\u503c\u8bbe\u7f6e\u9ad8\u5ea6\u3002\n <\/div>\n
\n \u5982\u679c\u4e00\u4e2a\u5143\u7d20\u5177\u6709\u591a\u4e2a\u80cc\u666f\u56fe\u50cf\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u9017\u53f7\u5206\u9694\u7684\u503c\u6765\u5b9a\u4e49\u6bcf\u4e2a\u80cc\u666f\u56fe\u50cf\u7684\u5927\u5c0f\u3002\n <\/div>\n
\n cover <\/strong>\u503c
\n background-size <\/strong>\u5c5e\u6027\u7528\u4e8e\u8986\u76d6\u5143\u7d20\u7684\u6574\u4e2a\u80cc\u666f\u533a\u57df\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u6b64\u5c5e\u6027\u7684
\n contain <\/strong>\u503c\u4f1a\u5c3d\u53ef\u80fd\u7f29\u653e\u56fe\u50cf\uff0c\u800c\u4e0d\u4f1a\u88c1\u526a\u56fe\u50cf\u3002\n <\/div>\n

\u8bed\u6cd5<\/h3>\n
\n
 background-size: auto | length | cover | contain | initial | inherit;
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6b64\u5c5e\u6027\u7684\u503c\u5b9a\u4e49\u5982\u4e0b\u3002\n <\/div>\n

\u5c5e\u6027\u503c<\/h3>\n
\n auto\uff1a<\/strong>\u8fd9\u662f\u9ed8\u8ba4\u503c\uff0c\u5b83\u5c06\u4ee5\u539f\u59cb\u5927\u5c0f\u663e\u793a\u80cc\u666f\u56fe\u50cf\u3002\n <\/div>\n
\n length\uff1a <\/strong>\uff1a\u7528\u4e8e\u8bbe\u7f6e\u80cc\u666f\u56fe\u50cf\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002\u8be5\u503c\u5728\u7ed9\u5b9a\u957f\u5ea6\u7684\u76f8\u5e94\u7ef4\u5ea6\u4e0a\u62c9\u4f38\u56fe\u50cf\u3002\u5b83\u7684\u5355\u4e2a\u503c\u6307\u5b9a\u56fe\u50cf\u7684\u5bbd\u5ea6\uff0c\u800c\u9ad8\u5ea6\u8bbe\u7f6e\u4e3a\u81ea\u52a8\u3002\u5982\u679c\u7ed9\u51fa\u4e24\u4e2a\u503c\uff0c\u5219\u7b2c\u4e00\u4e2a\u503c\u8bbe\u7f6e\u5bbd\u5ea6\uff0c\u7b2c\u4e8c\u4e2a\u503c\u8bbe\u7f6e\u9ad8\u5ea6\u3002\u4e0d\u5141\u8bb8\u4f7f\u7528\u8d1f\u503c\u3002\n <\/div>\n
\n percentage\uff1a<\/strong>\u5c06\u80cc\u666f\u56fe\u50cf\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u5b9a\u4e49\u4e3a\u80cc\u666f\u5b9a\u4f4d\u533a\u57df\u7684\u767e\u5206\u6bd4\uff08\uff05\uff09\u3002\u4e0d\u5141\u8bb8\u4f7f\u7528\u8d1f\u503c\u3002\n <\/div>\n
\n cover\uff1a<\/strong>\u7528\u4e8e\u8c03\u6574\u80cc\u666f\u56fe\u7247\u7684\u5927\u5c0f\u4ee5\u8986\u76d6\u6574\u4e2a\u5bb9\u5668\u3002\u6709\u65f6\uff0c\u5b83\u4f1a\u4ece\u8fb9\u7f18\u4e4b\u4e00\u4e0a\u4fee\u526a\u6389\u4e00\u70b9\u6216\u62c9\u4f38\u56fe\u50cf\u3002\n <\/div>\n
\n contain\uff1a<\/strong>\uff1a\u5728\u4e0d\u62c9\u4f38\u6216\u88c1\u526a\u7684\u60c5\u51b5\u4e0b\uff0c\u5b83\u8c03\u6574\u80cc\u666f\u56fe\u50cf\u7684\u5927\u5c0f\u4ee5\u786e\u4fdd\u56fe\u50cf\u5b8c\u5168\u53ef\u89c1\u3002\n <\/div>\n
\n initial\uff1a<\/strong>\u5c06\u5c5e\u6027\u8bbe\u7f6e\u4e3a\u5176\u9ed8\u8ba4\u503c\u3002\n <\/div>\n
\n inherit\uff1a<\/strong>\u5b83\u4ece\u5176\u7236\u5143\u7d20\u7ee7\u627f\u8be5\u5c5e\u6027\u3002\n <\/div>\n
\n \u901a\u8fc7\u4e00\u4e9b\u8bf4\u660e\uff0c\u8ba9\u6211\u4eec\u7406\u89e3
\n CSS\u5c5e\u6027\u3002\n <\/div>\n

\u793a\u4f8b<\/h3>\n
\n \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u5b58\u5728\u4e09\u4e2adiv\u5143\u7d20\uff0c\u5176\u5bbd\u5ea6\u4e3a300px\uff0c\u9ad8\u5ea6\u4e3a200px\u3002\u6bcf\u4e2adiv\u5143\u7d20\u90fd\u6709\u4e00\u4e2a\u80cc\u666f\u56fe\u7247\uff0c\u6211\u4eec\u5c06\u5728\u5176\u4e2d\u5e94\u7528
\n background-size <\/strong>\u5c5e\u6027\u3002\n <\/div>\n
\n \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4f7f\u7528\u957f\u5ea6\u548c\u767e\u5206\u6bd4\u503c\u6765\u8bbe\u7f6ediv\u7684\u80cc\u666f\u5927\u5c0f\u5143\u4ef6\u3002\u7b2c\u4e00\u4e2adiv\u5143\u7d20\u7684
\n \u80cc\u666f\u5c3a\u5bf8<\/strong>\u8bbe\u7f6e\u4e3a
\n \u81ea\u52a8<\/strong>\uff0c\u7b2c\u4e8c\u4e2adiv\u5143\u7d20\u7684\u8bbe\u7f6e
\n 150px 150px <\/strong>\uff0c\u5e76\u4e14
\n background-size <\/strong>\u7684\u7b2c\u4e09\u4e2adiv\u5143\u7d20\u8bbe\u7f6e\u4e3a
\n 30\uff05<\/strong>\u3002\n <\/div>\n
\n
 <!DOCTYPE html>
<html>
<head>
<title>
background-size property
<\/title>
<style>
div {
width: 300px;
height: 200px;
border: 2px solid red;
}
#div1{
background-image: url('lion.png');
background-size: auto;
}
#div2{
background-image: url('lion.png');
background-size: 150px 150px;
}
#div3{
background-image: url('lion.png');
background-size: 30%;
}
<\/style>
<\/head>
<body>
<h2> background-size: auto; <\/h2>
<div id = \"div1\"><\/div>
<h2> background-size: 150px 150px; <\/h2>
<div id = \"div2\"><\/div>
<h2> background-size: 30%; <\/h2>
<div id = \"div3\"><\/div>
<\/body>
<\/html>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa<\/strong>\n <\/div>\n

CSS background-size_https:\/\/bianchenghao6.com_\u3010CSS \u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n \u73b0\u5728\uff0c\u5728\u4e0b\u4e00\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528
\n background-size <\/strong>\u5c5e\u6027\u7684
\n cover\uff0ccontain\uff0c<\/strong>\u548c
\n initial <\/strong>\u503c\u3002\n <\/div>\n

\u793a\u4f8b<\/h3>\n
\n
 <!DOCTYPE html>
<html>
<head>
<title>
background-size property
<\/title>
<style>
div {
width: 300px;
height: 250px;
border: 2px solid red;
background-repeat: no-repeat;
}
#div1{
background-image: url('lion.png');
background-size: contain;
}
#div2{
background-image: url('lion.png');
background-size: cover;
}
#div3{
background-image: url('lion.png');
background-size: initial;
}
<\/style>
<\/head>
<body>
<h2> background-size: contain; <\/h2>
<div id = \"div1\"><\/div>
<h2> background-size: cover; <\/h2>
<div id = \"div2\"><\/div>
<h2> background-size: initial; <\/h2>
<div id = \"div3\"><\/div>
<\/body>
<\/html>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa<\/strong>\n <\/div>\n

CSS background-size_https:\/\/bianchenghao6.com_\u3010CSS \u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

\u793a\u4f8b-\u5408\u5e76\u591a\u4e2a\u56fe\u50cf<\/h3>\n
\n \u6211\u4eec\u8fd8\u53ef\u4ee5\u5408\u5e76\u6b64\u5c5e\u6027\u7684\u503c\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u591a\u4e2a\u56fe\u50cf\u3002\u53ef\u4ee5\u7528\u9017\u53f7\u5206\u9694\u7684\u8bed\u6cd5\u5b8c\u6210\u3002\n <\/div>\n
\n \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6709\u4e09\u4e2adiv\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u6709\u4e24\u4e2a\u80cc\u666f\u56fe\u50cf\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5728\u4e24\u4e2a\u56fe\u50cf\u4e0a\u90fd\u5e94\u7528\u4e86
\n background-size <\/strong>\u5c5e\u6027\u3002\n <\/div>\n
\n
 <!DOCTYPE html>
<html>
<head>
<title>
background-size property
<\/title>
<style>
div {
width: 250px;
height: 250px;
border: 2px solid red;
background-repeat: no-repeat;
background-position: center;
}
#div1{
background-image: url('lion.png'), url('forest.jpg');
background-size: 300px 150px, cover;
}
#div2{
background-image: url('lion.png'), url('forest.jpg');
background-size: 200px 150px, 300px 200px;
}
#div3{
background-image: url('lion.png'), url('forest.jpg');
background-size: 150px 175px, contain;
}
<\/style>
<\/head>
<body>
<h2> background-size: 300px 150px, cover; <\/h2>
<div id = \"div1\"><\/div>
<h2> background-size: 200px 150px, 300px 200px; <\/h2>
<div id = \"div2\"><\/div>
<h2> background-size: 150px 175px, contain; <\/h2>
<div id = \"div3\"><\/div>
<\/body>
<\/html>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa<\/strong>\n <\/div>\n

CSS background-size_https:\/\/bianchenghao6.com_\u3010CSS \u6559\u7a0b\u3011_\u7b2c3\u5f20
\n <\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[175],"tags":[],"class_list":["post-2351","post","type-post","status-publish","format-standard","hentry","category-css-jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2351"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=2351"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2351\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=2351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=2351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=2351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}