• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Css Basic: grid-template-columns

December 20, 2023

CSS Basics: grid-template-columns

In the world of web development, CSS (Cascading Style Sheets) plays a crucial role in designing and styling websites. One of the most powerful features of CSS is the ability to create responsive and flexible layouts using grid systems. In this article, we will explore the grid-template-columns property, which allows us to define the columns of a grid layout.

Understanding Grid Layouts

Before diving into grid-template-columns, let’s have a brief overview of CSS grid layouts. CSS grid is a two-dimensional layout system that allows us to create complex and flexible designs. It consists of rows and columns, forming a grid of cells where we can place our content.

With CSS grid, we can define the size and position of each cell, creating a responsive layout that adapts to different screen sizes. The grid-template-columns property is a fundamental part of this process.

The grid-template-columns Property

The grid-template-columns property is used to define the columns of a grid layout. It allows us to specify the width, size, and behavior of each column. We can define the columns using various units such as pixels, percentages, or fractions.

Here’s an example of how to use the grid-template-columns property:

.grid-container {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
}

In the above example, we have a grid container with three columns. The 1fr and 2fr values represent fractions of the available space. The first and third columns will take up one-third of the available space each, while the second column will take up two-thirds of the available space.

Using grid-template-columns with Auto and Fixed Sizes

The grid-template-columns property also allows us to specify fixed sizes for columns using pixels or other length units. We can also use the auto keyword to let the browser automatically determine the size of a column based on its content.

Here’s an example:

.grid-container {
  display: grid;
  grid-template-columns: 200px auto 300px;
}

In the above example, the first column has a fixed width of 200 pixels, the second column will automatically adjust its width based on the content, and the third column has a fixed width of 300 pixels.

Responsive Grid Layouts

One of the main advantages of CSS grid is its ability to create responsive layouts. By using media queries, we can change the number and behavior of columns based on the screen size.

Here’s an example:

.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 768px) {
  .grid-container {
    grid-template-columns: 1fr;
  }
}

In the above example, we have a grid container with two columns. However, when the screen size is less than or equal to 768 pixels, the layout changes to a single column.

Conclusion

The grid-template-columns property is a powerful tool for creating flexible and responsive grid layouts. It allows us to define the columns of a grid and control their size and behavior. By combining it with other CSS grid properties and media queries, we can create visually appealing and adaptable designs for our websites.

Learn More About Server.HK

If you’re interested in VPS hosting solutions, Server.HK offers top-notch services. With their reliable and high-performance VPS hosting plans, you can ensure the smooth operation of your website. Check out their website for more information on Hong Kong VPS Hosting.

Recent Posts

  • How to Deploy a Node.js Application on Hong Kong VPS: Complete Guide
  • How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  • How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  • CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  • Top 5 Use Cases for a Hong Kong Dedicated Server in 2026

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot