Startec

Startec

A Must save CSS grid Technique ! (with code)

Mai 21, às 20:42

·

2 min de leitura

·

0 leituras

Grids are everywhere, you encounter them everywhere from browsing the images on Google to looking at the latest movies and shows on OTT platforms, but sometimes grid is difficult to implement with only CSS....
A Must save CSS grid Technique ! (with code)

Cover image for A Must save CSS grid Technique ! (with code)

jeetvora331

Grids are everywhere, you encounter them everywhere from browsing the images on Google to looking at the latest movies and shows on OTT platforms, but sometimes grid is difficult to implement with only CSS. In this article let's look at my go to code snippet for grid implementation.

The CSS properties repeat(auto-fit, minmax(240px, 1fr)) are used to create a responsive grid layout without using media queries. Let's break down each part of this property:

  • The minmax() function is a built-in CSS grid function used to set a range of width In this case, the minimum value is 240px, and the maximum value is 1fr.
  • The auto-fit keyword is used to automatically place grid items, filling the available space. This property helps create a responsive layout without using media queries
  • The repeat() function is used to define a pattern of grid columns or rows.

Look at this example:

Image description

And when the display size changes,

Image description

Code for the Example:
HTML

<div class="container">
 <div>Item 1</div>
 <div>Item 2</div>
 <div>Item 3</div>
 <div>Item 4</div>
 <div>Item 5</div>
 <div>Item 6</div>
 <div>Item 7</div>
 <div>Item 8</div>
 <div>Item 9</div>
 <div>Item 10</div>
 <div>Item 11</div>
 <div>Item 12</div>
 <div>Item 13</div>
</div>

Enter fullscreen mode Exit fullscreen mode

CSS:

.container {
 display: grid;
 grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
 grid-gap: 1rem;
}
.container > div{
 background: cyan;
 padding: 50px;
 border-style: solid; 
 border-width: 1px; 
}

Enter fullscreen mode Exit fullscreen mode

Also by default the root font size is 16px, so we can convert the 240px to 15rem. So in this example, the grid will automatically adjust the number of columns based on the available space, ensuring that each column is at least 240px (or 15rem) wide and distributing the remaining space equally among the columns.

grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));


Continue lendo

Marktechpost AI Research News

Perp-Neg: Unveiling Image Potential with Negative Prompts and Stable Diffusion
Despite the remarkable capabilities demonstrated by advancements in generating images from text using diffusion models, the accuracy of the generated images in conveying the intended meaning of the original text prompt is not always guaranteed, as found by recent research. Generating images that effectively align with the semantic content of the text query is a […]

Hoje, às 02:51

AI | Techcrunch

Marvel’s Spider-Man 2 features Miles with web wings and Peter in symbiote suit
Sony held its PlayStation Showcase on Wednesday, revealing for the first time 10 minutes of gameplay for the highly anticipated Spider-Man 2 video game. Fans also saw a short clip dedicated to the game’s...

Mai 24, às 22:28

Discovery

Google celebra o Big Mango na Austrália com Doodle
O Google está celebrando o Big Mango da Austrália, um ícone de viagem e destino turístico construído em homenagem à indústria agrícola de Bowen. A estrutura é um dos muitos “Big Things” em todo o país – uma...

Mai 24, às 22:27

AI | Techcrunch

Elon Musk ushers in DeSantis’s 2024 campaign, signaling a new era for Twitter
Twitter, once synonymous with Trump, is Musk's media machine now Florida Governor Ron DeSantis filed the paperwork to officially launch his presidential campaign this afternoon, but opted to...

Mai 24, às 22:14

Discovery

WhatsApp está desenvolvendo recurso de nome de usuário em sua última atualização beta para Android
O WhatsApp continua sua busca por melhorias na experiência do usuário, e agora está trabalhando em um recurso de nome de usuário. Na versão beta mais recente do WhatsApp para Android 2.23.11.15, o app ganhou...

Mai 24, às 21:46

AI | Techcrunch

Snowflake acquires Neeva to bring intelligent search to its cloud data management solution
Snowflake is all about managing data in the cloud, whether as part of a structured data warehouse, or less structured data lake. Neeva, a search startup from two former Google employees, has been all about...

Mai 24, às 21:35

HackerNoon

These Technical Skills Are Extremely Useful for Test Automation | HackerNoon
These Technical Skills Are Extremely Useful for Test Automation [email protected] Long; Didn't ReadIf you work as a manual tester but want to transition to test automation, then you’ll need a few technical...

Mai 24, às 21:30

HackerNoon

Meet the Writer: HackerNoon Contributor Jin Park - Technical Writer | HackerNoon
Meet the Writer: HackerNoon Contributor Jin Park - Technical Writer [email protected] Long; Didn't ReadJin is a freelancing whizz-kid with a love for tech, the intricate dance of neuroscience, and a knack for...

Mai 24, às 21:02

freeCodeCamp

How Security Analysts Can Use Artificial Intelligence (AI) in Cybersecurity
Artificial intelligence (AI) has been a game-changer in cybersecurity. It has revolutionized the approach to cybersecurity by providing advanced techniques to detect and mitigate cyber threats. The use of AI in cybersecurity is increasing rapidly, with many companies adopting it as a key tool in their cybersecurity strategy.

Mai 24, às 20:58

Showmetech

TUDO sobre Final Fantasy XVI, aguardadíssimo RPG da Square Enix
Índice Estamos quase lá, só mais um mês de esperaO que se passa no mundo do jogoOs personagens do jogo e o decorrer de suas vidas Um gameplay cheio de ação e variedadeE os outros aspectos do jogo, como a...

Mai 24, às 20:00