Modern CSS function - clamp()

Modern CSS function - clamp()

Are you still using static width to size your wrapper/container??? its time to switch to the clamp function. You can use clamp() in CSS to size your wrapper/container element. An example is hereunder:

clamp(min, val, max)

min the smallest unit you ever want

max the biggest unit you ever want


val the ideal unit
/**
 * WRAPPER
 * Sets a max width, adds a consistent gutter and horizontally
 * centers the contents
 */

.wrapper{

 width: 90vw;
 width: clamp(16rem, 90vw, 70rem);
 margin-left: auto;
 margin-right: auto;
 padding-left: 1.5rem;
 padding-right: 1.5rem;
 position: relative;

}


It gives you more fine-grained control and really improves line-lengths and readability on medium viewports, like portrait tablets.

Reference:

https://piccalil.li/quick-tip/use-css-clamp-to-create-a-more-flexible-wrapper-utility

https://www.youtube.com/watch?v=Rw9GZ52P4mY


要查看或添加评论,请登录

Moeed Khan的更多文章

  • Why Everyone's Talking About DeepSeek

    Why Everyone's Talking About DeepSeek

    DeepSeek is a relatively new AI model that has been gaining a lot of attention lately. It is a large language model…

  • Use svh or dvh instead of vh

    Use svh or dvh instead of vh

    Hey web devs! Tired of those annoying mobile scrolls messing up your perfectly-sized elements? Meet svh and dvh –…

  • Download Free Shopify Theme

    Download Free Shopify Theme

    Give Your Store the Premium Treatment (for FREE!) Sleek design Effortless shopping And features that'll have your…

    1 条评论
  • Crypto phishing scam (via CRYPTONCOIN. NET) – Lost bag

    Crypto phishing scam (via CRYPTONCOIN. NET) – Lost bag

    Be aware of this #scam : The senders email appears to be quite genuine! Sender : Sadiq Zaidi sadiq.zaidi@synageglobal.

  • Workplace Issues | Stand for your rights OR you don't have a right to fingerprint others!

    Workplace Issues | Stand for your rights OR you don't have a right to fingerprint others!

    Workplace Issues Interpersonal conflict Bullying Harassment Discrimination It's a sad fact that the world is talking…

  • Text to speech in two lines only

    Text to speech in two lines only

    Try this cool Javascript 2 lines of code and hear your web talking ;-). Basic Implementation: https://gearepublic.

  • schema.org/Restaurant , schema.org/AggregateRating

    schema.org/Restaurant , schema.org/AggregateRating

    TYPES: #eg-0004 Restaurant, AggregateRating, FoodEstablishment, LocalBusiness, aggregateRating, ratingValue…

  • schema.org/Painting

    schema.org/Painting

    TYPES: #eg-0003 Painting, genre PRE-MARKUP: The Madonna with the Long Neck Late Renaissance painting by Parmigianino…

  • Remove image backgrounds automatically in 5 seconds

    Remove image backgrounds automatically in 5 seconds

    You don't know Photoshop OR you don't have hours to edit an image. let me tell you the easiest and free way to remove…

  • Forms Best Practices

    Forms Best Practices

    :valid and :invalid CSS pseudo-classes input:invalid { border: 1px dotted red; color: hotpink; } To set…

社区洞察

其他会员也浏览了