clamp කාර්යය

clamp කාර්යය පරාමිතීන් තුනක් ලබා ගනී: අවම අගය, අපේක්ෂිත අගය සහ උපරිම අගය. එය පහත දේ ආපසු ලබා දෙයි:

වාක්‍ය ඛණ්ඩය

cssතෝරන්නා {
  ගුණාංගය: clamp(min, pref, max);
}

උදාහරණය . බ්ලොක් වල ප්‍රමාණය සීමා කිරීම

පහත උදාහරණයේ දී, බ්ලොකයේ අපේක්ෂිත ප්‍රමාණය තිරයේ පළලෙන් 30% වේ. නමුත් එය 100px ට වඩා අඩු හෝ 300px ට වඩා වැඩි විය නොහැක:

html<div id="con1"></div>
<div id="targ"></div>
<div id="con2"></div>
css#targ {
  width: clamp(100px, 30%, 300px);
  height: 100px;
  border: 1px solid red;
  margin: 30px auto;
}
#con1 {
  width: 100px;
  height: 100px;
  border: 1px solid black;
  margin: 30px auto;
}
#con2 {
  width: 300px;
  height: 100px;
  border: 1px solid black;
  margin: 30px auto;
}

Результат:

උදාහරණය . අනුවර්තී අකුරු ප්‍රමාණය

පහත උදාහරණයේ දී, අකුරු ප්‍රමාණයේ අපේක්ෂිත අගය 4vw වේ. නමුත් එය 16px ට වඩා අඩු හෝ 32px ට වඩා වැඩි විය නොහැක:

html<p id="con1">
  responsive text example
</p>
<p id="elem">
  responsive text example
</p>
<p id="con2">
  responsive text example
</p>
css#elem {
  font-size: clamp(16px, 4vw, 32px);
  color: red;
}
#con1 {
  font-size: 16px;
}
#con2 {
  font-size: 32px;
}

Результат:

උදාහරණය . අනුවර්තී වටකුරු අරය

පහත උදාහරණයේ දී, වටකුරු අරයේ අපේක්ෂිත අගය 3vw වේ. නමුත් එය 5px ට වඩා අඩු හෝ 20px ට වඩා වැඩි විය නොහැක:

html<div id="con1"></div>
<div id="elem"></div>
<div id="con2"></div>
cssdiv {
  width: 100px;
  height: 100px;
  margin: 20px auto;
  background: lightblue;
}
#elem {
  border-radius: clamp(5px, 3vw, 20px);
  background: #efafc6;
}
#con1 {
  border-radius: 5px;
}
#con2 {
  border-radius: 20px;
}

Результат:

මේවාද බලන්න

  • min කාර්යය,
    අවම අගය තෝරා ගන්නා
  • max කාර්යය,
    උපරිම අගය තෝරා ගන්නා