ﺭﺩ ﺍﺭ ﻪﯿﺷﺎﺣ ﻭ padding ﻪﮐ ﺪﻫﺩ ﯽﻣ ﺍﺭ ﻥﺎﮑﻣﺍ ﻦﯾﺍ ﺎﻣ ﻪﺑ :ﺩﻮﺷ ﯽﻣ ﻪﺒﺳﺎﺤﻣ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﺮﺼﻨﻋ ﮏﯾ ﻉﺎﻔﺗﺭﺍ ﻭ ﺽﺮﻋ ،ﺽﺮﻓ ﺶﯿﭘ ﺭﻮﻃ ﻪﺑ ﺩﻮﺷ ﯽﻣ ﺮﻫﺎﻇ ﺐﻠﻏﺍ ﺮﺼﻨﻋ ،ﺪﯿﻨﮐ ﯽﻣ ﻢﯿﻈﻨﺗ ﺍﺭ ﺮﺼﻨﻋ ﮏﯾ ﻉﺎﻔﺗﺭﺍ/ﺽﺮﻋ ﯽﺘﻗﻭ :ﺖﺳﺍ ﯽﻨﻌﻣ ﻦﯾﺍ ﺪﻫﺩ ﯽﻣ ﻥﺎﺸﻧ ﻥﺎﺴﮑﯾ ﺎﺑ ﺍﺭ <div> ﺮﺼﻨﻋ ﻭﺩ ﺮﯾﺯ ﺮﯾﻮﺼﺗ ﺪﻧﻮﺷ ﯽﻣ ﻢﺘﺧ ﯽﺗﻭﺎﻔﺘﻣ ﯼﺎﻫ ﻩﺯﺍﺪﻧﺍ ﻪﺑ ﻪﺠﯿﺘﻧ ﺭﺩ ﻻﺎﺑ <div> ﺮﺼﻨﻋ ﻭﺩ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺩﻮﺷ ﯽﻣ ﻞﺣ .ﻢﯿﻫﺩ ﺭﺍﺮﻗ ﺮﺼﻨﻋ ﻞﮐ ﻉﺎﻔﺗﺭﺍ ﻭ ﺽﺮﻋ ﺭﺩ ﺍﺭ ﻪﯿﺷﺎﺣ ﻭ ﮏﺘﺸﻟﺎﺑ ﻪﮐ ﺪﻫﺩ ﯽﻣ ﺍﺭ ﻥﺎﮑﻣﺍ ﻦﯾﺍ ﺎﻣ :ﺪﻧﺮﯿﮔﯽﻣ ﺭﺍﺮﻗ ﻉﺎﻔﺗﺭﺍ ﻭ ﺽﺮﻋ ﺭﺩ ﻪﯿﺷﺎﺣ ﻭ ﮏﺘﺸﻟﺎﺑ ،ﺪﯿﻨﮐ ﻢﯿﻈﻨﺗ ﺮﺼﻨﻋ ﮏﯾ ﯼﻭﺭ ﺍﺭ < → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﻨﻨﮐ ﺭﺎﮐ ﻞﮑﺷ ﻦﯾﺍ ﻪﺑ ﺎﻬﻧﺁ ﺕﺎﺤﻔﺻ ﺭﺩ ﺩﻮﺟﻮﻣ ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﺪﻨﻫﺍﻮﺧ ﯽﻣ ﻥﺎﮔﺪﻨﻫﺩ ﻪﻌﺳﻮﺗ ﺯﺍ .( ;%100 :ﺪﻨﺳﺭﯽﻣ ﺮﻈﻧ ﻪﺑ ﺕﻭﺎﻔﺘﻣ ﺽﺮﻋ ﺭﺩ ﻦﺘﻣ ﯽﺣﺍﻮﻧ ﻭ ﺎﻫﯼﺩﻭﺭﻭ ﻪﮐ ﺖﺳﺍ ﻞﯿﻟ :ﺖﺳﺍ ﻪﻧﻼﻗﺎﻋ ﻭ ﻦﻤﯾﺍ ﺮﺻﺎﻨﻋ ﻪﻤﻫ ﯼﺍﺮﺑ ﺩﺭﻮﻣ ﻦﯾﺍ ﻝﺎﻤﻋﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺪﯾﺎﺑ :ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﺍﺭ ﺮﺼﻨﻋ ﮏﯾ ﻉﺎﻔﺗﺭﺍ ﻭ ﺽﺮﻋ ﻪﺒﺳﺎﺤﻣ ﻩﻮﺤﻧ
ﺮﺼﻨﻋ ﮏﯾ ﯽﻌﻗﺍﻭ ﺽﺮﻋ=ﻪﯿﺷﺎﺣ + ﮏﺘﺸﻟﺎﺑ + ﺽﺮﻋ
ﻝﺎﺜﻣ
.div1 {
width: 300px;
height:
100px;
border: 1px solid blue;
}
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
}
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
width: 300px;
height: 100px;
border: 1px solid blue;
}
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
}
</style>
</head>
<body>
<h1>Without box-sizing</h1>
<div class="div1">This div is smaller (width is 300px and height is 100px).</div>
<br>
<div class="div2">This div is bigger (width is also 300px and height is 100px).</div>
</body>
</html>
box-sizing
ﯽﮔﮋﯾﻭ CSS box-sizing ﯽﮔﮋﯾﻭ ﺎﺑ
box-sizing: border-box;
ﺎﺑ ،ﺖﺳﺍ ﻻﺎﺑ ﻝﺎﺜﻣ ﻥﺎﻤﻫ ﻝﺎﺜﻣ
.div1 {
width: 300px;
height:
100px;
border: 1px solid blue;
box-sizing: border-box;
}
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
.div1 {
width: 300px;
height: 100px;
border: 1px solid blue;
box-sizing: border-box;
}
.div2 {
width: 300px;
height: 100px;
padding: 50px;
border: 1px solid red;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>With box-sizing</h1>
<div class="div1">Both divs are the same size now!</div>
<br>
<div class="div2">Hooray!</div>
</body>
</html>
ﻝﺎﺜﻣ
* {
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
* {
box-sizing: border-box;
}
input, textarea {
width: 100%;
}
</style>
</head>
<body>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br>
Comments:<br>
<textarea name="message" rows="5" cols="30">
</textarea>
<br><br>
<input type="submit" value="Submit">
</form>
<p><strong>Tip:</strong> Try to remove the box-sizing property from the style element and look what happens.
Notice that the width of input, textarea, and submit button will go outside of the screen.</p>
</body>
</html>
CSS ﻪﺒﻌﺟ ﻩﺯﺍﺪﻧﺍ ﯽﮔﮋﯾﻭ