ﻩﻮﺤﻧ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ ﺩﻮﺷ ﻩﺩﺎﻔﺘﺳﺍ ﺪﯾﺎﺑ <video> ﺎﯾ <img> ﮏﯾ ﻪﻧﻮﮕﭼ ﻪﮑﻨﯾﺍ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺮﯾﺯ ﻞﮑﺷ ﻪﺑ ،ﻢﯿﻨﮐ (ﻞﺴﮑﯿﭘ 300) ﻉﺎﻔﺗﺭﺍ ﻥﺎﻤﻫ ﻭ (ﻞﺴﮑﯿﭘ 200) ﻥﺁ ﺽﺮﻋ ﻒﺼﻧ ﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺩﺮﯿﮔ ﺭﺍﺮﻗ ﻞﺴﮑﯿﭘ 200x300 ﻑﺮﻇ ﺭﺩ ﺎﺗ ﺖﺳﺍ ﻥﺪﺷ ﻩﺩﺮﺸﻓ ﻝﺎﺣ ﺭﺩ ﺮﯾﻮﺼﺗ ﻪﮐ ﻢﯿﻨﯿﺑ ﯽﻣ ﺪﯾﺁ ﯽﻣ .ﺪﻨﮐ ﯽﻣ ﻆﻔﺣ ﺍﺭ ﺩﻮﺧ ﺩﺎﻌﺑﺍ ﺖﺒﺴﻧ ﺮﯾﻮﺼﺗ ،ﻢﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻨﮐﯽﻣ ﺮﯿﯿﻐﺗ ﻩﺪﺷ ﻩﺩﺍﺩ ﺪﻌﺑ ﺭﺩ ﻦﺘﻓﺮﮔ ﺭﺍﺮﻗ ﯼﺍﺮﺑ ﻥﺁ ﻩﺯﺍﺪﻧﺍ ﺎﻣﺍ ،ﺪﻨﮐﯽﻣ ﻆﻔ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﻮﺷ ﺐﺳﺎﻨﻣ ﺎﺗ ﺩﻮﺷ ﯽﻣ ﻩﺩﺮﺸﻓ ﺎﯾ ﻩﺪﯿﺸﮐ ﺮﯾﻮﺼﺗ ،ﻡﻭﺰﻟ ﺕﺭﻮﺻ ﺭﺩ .ﺪﻨﮐ ﯽﻣ ﺮﯿﯿﻐﺗ ﻩﺪﺷ ﻩﺩﺍﺩ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻨﮐ ﯽﻤﻧ ﺮﯿﯿﻐﺗ ﺮﯾﻮﺼﺗ ﻩﺯﺍﺪﻧﺍ ﻢﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ <"code class="w3-codespan> ﺎﯾ .ﺩﻮﺷ ﯽﻣ ﮏﭼﻮﮐ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﻨﮐ ﺮﭘ ﺍﺭ ﻉﺎﻔﺗﺭﺍ ﺪﺻﺭﺩ 100 ﻭ ﺮﮔﺭﻭﺮﻣ ﻩﺮﺠﻨﭘ ﺪﺻﺭﺩ 50 ﺽﺮﻋ ﻢﯿﻫﺍﻮﺧ ﯽﻣ ﻭ ﻢﯾﺭﺍﺩ ﺮﯾﻮﺼﺗ :ﺩﻭﺭ ﯽﻣ ﻦﯿﺑ ﺯﺍ ﺮﯾﻭﺎﺼﺗ ﺩﺎﻌﺑﺍ ﺖﺒﺴﻧ ،ﻢﯿﻫﺩ ﯽﻣ ﺮﯿﯿﻐﺗ ﺍﺭ ﺮﮔﺭﻭﺮﻣ ﻩﺮﺠﻨﭘ ﻩﺯﺍﺪﻧﺍ ﯽﺘﻗﻭ ﻦﯾ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺩﻮﺷﯽﻣ ﻆﻔﺣ ﺮﯾﻭﺎﺼﺗ ﺩﺎﻌﺑﺍ ﺖﺒﺴﻧ ،ﻢﯿﻫﺩﯽﻣ ﺮﯿﯿﻐﺗ ﺍﺭ ﺮﮔﺭﻭﺮﻣ ﻩﺮﺠﻨﭘ ﻩﺯﺍﺪﻧﺍ ﯽﺘ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﺍﺭ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ :ﺪﻨﮐ ﯽﻣ ﺖﺳﺮﻬﻓ ﺍﺭ *-CSS object ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺮﯾﺯ ﻝﻭﺪﺟ ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺖﻘﺑﺎﻄﻣ ﻥﺁ ﻑﺮﻇ ﺎﺑ ﺎﺗ ﺩﻮﺷ ﻩﺩﺍﺩ ﻩﺯﺍﺪﻧﺍ ﺮﯿﯿﻐﺗ ﺪﯾﺎﺑ <video> ﺎﯾ <img> ﮏﯾ ﺪﻨﮐﯽﻣ ﺺﺨﺸﻣ x/y ﺎﺑ ﺍﺭ <video> ﺎﯾ <img> ﯼﺮﯿﮔﺭﺍﺮﻗ ﻩﻮﺤﻧ CSS ﺐﺳﺎﻨﻣ ﯽﺷ ﯽﮔﮋﯾﻭ
ﻝﺎﺜﻣ
img {
width: 200px;
height:
300px;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width:200px;
height:300px;
}
</style>
</head>
<body>
<h2>Image</h2>
<img src="paris.jpg" alt="Paris" width="400" height="300">
</body>
</html>
object-fit
ﯽﮔﮋﯾﻭ ﻪﮐ ﺖﺳﺍ ﯽﯾﺎﺟ ﺎﺠﻨﯾﺍﺮﭘ
- ﺶﯿﭘ ﻦﯾﺍﺩﻮﺷ ﺮﭘ ﺎﺗ ﺪﻨﮐ ﯽﻣ ﺮﯿﯿﻐﺗ ﺮﯾﻮﺼﺗﯼﻭﺎﺣ
- ﺮﯾﻮﺼﺗﺪﻠﺟ
- ﺪﻨﮐ ﯽﻣ ﻆﻔﺣ ﺍﺭ ﺩﻮﺧ ﺩﺎﻌﺑﺍ ﺖﺒﺴﻧ ﺮﯾﻮﺼﺗﭻﯿﻫ
- ﺖﺳﺍ ﻩﺩﺮﮑﻧ ﺮﯿﯿﻐﺗ ﺮﯾﻮﺼﺗ ﻩﺯﺍﺪﻧﺍﺱﺎﯿﻘﻣ ﺶﻫﺎﮐ
- ﺖﺳﺍ ﺮﯾﻮﺼﺗ .ﺶﺷﻮﭘ :ﺖﯿﻓ ءﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
ob
ﻝﺎﺜﻣ
img {
width: 200px;
height:
300px;
object-fit: cover;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 200px;
height: 300px;
object-fit: cover;
}
</style>
</head>
<body>
<h2>Using object-fit: cover</h2>
<img src="paris.jpg" alt="Paris" width="400" height="300">
</body>
</html>
;contain :ﺖﯿﻓ ءﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
ﻝﺎﺜﻣ
img {
width: 200px;
height:
300px;
object-fit: contain;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 200px;
height: 300px;
object-fit: contain;
}
</style>
</head>
<body>
<h2>Using object-fit: contain</h2>
<img src="paris.jpg" alt="Paris" width="400" height="300">
</body>
</html>
;fill :ﺖﯿﻓ ءﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
ﻝﺎﺜﻣ
img {
width: 200px;
height:
300px;
object-fit: fill;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 200px;
height: 300px;
object-fit: fill;
}
</style>
</head>
<body>
<h2>Using object-fit: fill</h2>
<img src="paris.jpg" alt="Paris" width="400" height="300">
</body>
</html>
.ﭻﯿﻫ :ﺖﯿﻓ ءﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
object-fit:
ﻝﺎﺜﻣ
img {
width: 200px;
height:
300px;
object-fit: none;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 200px;
height: 300px;
object-fit: none;
}
</style>
</head>
<body>
<h2>Using object-fit: none</h2>
<img src="paris.jpg" alt="Paris" width="400" height="300">
</body>
</html>
.ﺱﺎﯿﻘﻣ ﺶﻫﺎﮐ :ﺐﺳﺎﻨﻣ ءﯽﺷ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ
ﭻﯿﻫ<"code class="w3-codespan
ﻝﺎﺜﻣ
img {
width: 200px;
height:
300px;
object-fit: scale-down;
}
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 200px;
height: 300px;
object-fit: scale-down;
}
</style>
</head>
<body>
<h2>Using object-fit: scale-down</h2>
<img src="paris.jpg" alt="Paris" width="400" height="300">
</body>
</html>
ﺮﮕﯾﺩ ﯽﻟﺎﺜﻣ
ﻝﺎﺜﻣ
<!DOCTYPE html>
<html>
<body>
<h2>Not Using object-fit</h2>
<p>Here we use do not use "object-fit", so when we resize the browser window, the aspect ratio of the images will be destroyed:</p>
<div style="width:100%;height:400px;">
<img src="rock600x400.jpg" alt="Norway" style="float:left;width:50%;height:100%;">
<img src="paris.jpg" alt="Paris" style="float:left;width:50%;height:100%;">
</div>
</body>
</html>
ﻝﺎﺜﻣ
<!DOCTYPE html>
<html>
<body>
<h2>Using object-fit</h2>
<p>Here we use "object-fit: cover;", so when we resize the browser window, the aspect ratio of the images is preserved:</p>
<div style="width:100%;height:400px;">
<img src="rock600x400.jpg" alt="Norway" style="float:left;width:50%;height:100%;object-fit:cover;">
<img src="paris.jpg" alt="Paris" style="float:left;width:50%;height:100%;object-fit:cover;">
</div>
</body>
</html>
CSS object-fit ﺮﺘﺸﯿﺑ ﯼﺎﻫ ﻝﺎﺜﻣ
object-fit
ﯽﮔﮋﯾﻭ ﻦﮑﻤﻣ ﺮﯾﺩﺎﻘﻣ ﻝﺎﺜﻣ
.fill {object-fit: fill;}
.contain {object-fit: contain;}
.cover {object-fit: cover;}
.scale-down {object-fit: scale-down;}
.none {object-fit: none;}
<!DOCTYPE html>
<html>
<head>
<style>
.fill {object-fit: fill;}
.contain {object-fit: contain;}
.cover {object-fit: cover;}
.scale-down {object-fit: scale-down;}
.none {object-fit: none;}
</style>
</head>
<body>
<h1>The object-fit Property</h1>
<h2>No object-fit:</h2>
<img src="paris.jpg" alt="Paris" style="width:200px;height:300px">
<h2>object-fit: fill (this is default):</h2>
<img class="fill" src="paris.jpg" alt="Paris" style="width:200px;height:300px">
<h2>object-fit: contain:</h2>
<img class="contain" src="paris.jpg" alt="Paris" style="width:200px;height:300px">
<h2>object-fit: cover:</h2>
<img class="cover" src="paris.jpg" alt="Paris" style="width:200px;height:300px">
<h2>object-fit: scale-down:</h2>
<img class="scale-down" src="paris.jpg" alt="Paris" style="width:200px;height:300px">
<h2>object-fit: none:</h2>
<img class="none" src="paris.jpg" alt="Paris" style="width:200px;height:300px">
</body>
</html>
CSS Object-* Properties