Related Topics
Introduction
Html page 1
Html page 2
Html page3
Html page4
HTML Elements and structure
Html page 5
Html page 6
Html page 7
HTML Headings and Paragraphs
Html page 8
Html page 9
Html page 10
HTML Lists and Tables
Html page 11
Html page 12
Html page 13
HTML Forms and Input Fields
Html page 14
Html page 15
Html page 16
HTML Images and Media
Html page 17
Html page 18
HTML Links and Anchors
Html page 19
Html page 20
Html page 21
HTML Styles and Formatting
Html page 22
HTML Semantic Elements
Html page 23
Html page 24
HTML Attributes
Html page 25
Html page 26
HTML JavaScript Integration
Html page 27
Html page 28
Html page 29
Html page 30
HTML Document and Browser Support
Html page 31
Html page 32
HTML5 New Elements and Attributes
Html page 33
Html page 34
Html page 35
Html page 36
HTML Accessibility and Web Standards
Html page 37
Html page 38
Html page 39
HTML Responsive Design and Mobile Devices.
Html page 40
Html page 41
Html page 42
Introduction
Data Structure Page 1
Data Structure Page 2
Data Structure Page 3
Data Structure Page 4
Data Structure Page 5
Data Structure Page 6
Data Structure Page 7
Data Structure Page 8
String
Data Structure Page 9
Data Structure Page 10
Data Structure Page 11
Data Structure Page 12
Data Structure Page 13
Array
Data Structure Page 14
Data Structure Page 15
Data Structure Page 16
Data Structure Page 17
Data Structure Page 18
Linked List
Data Structure Page 19
Data Structure Page 20
Stack
Data Structure Page 21
Data Structure Page 22
Queue
Data Structure Page 23
Data Structure Page 24
Tree
Data Structure Page 25
Data Structure Page 26
Binary Tree
Data Structure Page 27
Data Structure Page 28
Heap
Data Structure Page 29
Data Structure Page 30
Graph
Data Structure Page 31
Data Structure Page 32
Searching Sorting
Data Structure Page 33
Hashing Collision
Data Structure Page 35
Data Structure Page 36

CSS
.container {
display: grid;
}
2. Defining Grid Rows and Columns:
Once the container is a grid container, you can define the rows and columns of the grid using the
grid-template-rows
andgrid-template-columns
properties.You can specify the size of each row and column using various units (e.g., pixels, percentages, fractions) or use keywords like
auto
to automatically adjust the size.
For example:
.container {
display: grid;
grid-template-rows: 100px 200px; /* Defines two rows: first row with a height of 100px and second row with a height of 200px */
grid-template-columns: 1fr 2fr; /* Defines two columns: first column takes 1 fraction of available space, second column takes 2 fractions */
}
3. Placing Grid Items:
Grid items are the child elements of the grid container.
You can position and place grid items within the grid using the
grid-row
andgrid-column
properties or their shorthand,grid-area
.By specifying the starting and ending positions of rows and columns, you can control where the grid items are placed.
For example:
.item {
grid-row: 1 / 3; /* Item occupies rows 1 and 2 */
grid-column: 1 / 2; /* Item occupies columns 1 */
}
4. Grid Template Areas:
Grid template areas provide a convenient way to visually define and arrange grid items.
You can assign names to specific grid areas and then use the
grid-template-areas
property on the container to define the layout using those area names.For example:
.container {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.item {
grid-area: header; /* Places the item in the 'header' grid area */
}
Grid templates offer a flexible and powerful layout system. You can combine and nest grids, control spacing between rows and columns using properties like grid-gap
or gap
, and use features like auto-placement and alignment to create intricate designs. CSS Grid provides extensive capabilities to handle complex layouts, making it a valuable tool for web developers.
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
}
.item {
/* Styles for grid items */
}
2. Use media queries to modify the grid template for different viewport sizes:
Inside a media query, adjust the grid template by modifying the number of columns or changing their sizes.
You can use CSS functions like
repeat()
,minmax()
, or specify fixed sizes using units (e.g., pixels, percentages).
For example, for smaller viewports, you might want to switch to a single column layout:
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
}
}
3. Optionally, modify other aspects of the grid layout:
You can adjust row heights, grid gaps, or any other properties to optimize the layout for different screen sizes.
Consider using the
grid-auto-rows
property to set a minimum height for rows if necessary.
For example:
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
grid-auto-rows: 200px; /* Set a minimum height for rows */
grid-gap: 20px;
}
}
4. Repeat steps 2 and 3 as needed:
You can add additional media queries and adjust the grid template to accommodate more viewport sizes.
This allows you to create breakpoints and adapt the grid layout for different devices and screen widths.
By using media queries and adjusting the grid template, you can create responsive grid layouts that adapt to various screen sizes. Remember to test and fine-tune the layout across different devices and use CSS properties like grid-gap
, grid-auto-rows
, or alignment properties (justify-items
, align-items
, etc.) to further refine the responsive behavior of your grid.
.container {
display: grid;
grid-template-columns: minmax(200px, 1fr) minmax(100px, 2fr) minmax(150px, 1fr);
grid-template-rows: minmax(150px, 1fr);
grid-gap: 10px;
}
.item {
/* Styles for grid items */
}
In the above example, the grid items will have a minimum width of 200 pixels, 100 pixels, and 150 pixels, respectively. However, they can expand and shrink based on the available space within the grid container.
By leveraging the fr
unit and minmax()
function, you can create flexible and responsive grid layouts that adapt to the size of the container while providing control over the minimum and maximum sizes of grid items.
<div class="container">
<header class="header">Header</header>
<main class="main">Main Content</main>
<footer class="footer">Footer</footer>
</div>
CSS:
.container {
display: grid;
grid-template-rows: auto 1fr auto; /* Header, Main Content, Footer */
grid-template-columns: 1fr 1fr; /* Two equal-width columns */
grid-gap: 10px; /* Gap between grid items */
height: 100vh; /* Optional: Set the container height to the viewport height */
}
.header, .footer {
grid-column: 1 / 3; /* Span across both columns */
}
.main {
grid-column: 1 / 3; /* Span across both columns */
}
In this example, the .container
represents the grid container, and .header
, .main
, and .footer
represent the grid items.
By setting grid-template-rows
to auto 1fr auto
, we allocate the necessary space for the header and footer, and the remaining space is assigned to the main content area.
Using grid-template-columns: 1fr 1fr
, we create two equal-width columns.
To make the header and footer span across both columns, we set grid-column: 1 / 3
.
Finally, we can adjust the height of the container with height: 100vh
to make it occupy the full height of the viewport. This is optional and can be adjusted according to your requirements.
Feel free to modify the content and styles within the grid items (header
, main
, footer
) as per your specific design needs.




Popular Category
Topics for You
Introduction
Html page 1
Html page 2
Html page3
Html page4
HTML Elements and structure
Html page 5
Html page 6
Html page 7
HTML Headings and Paragraphs
Html page 8
Html page 9
Html page 10
HTML Lists and Tables
Html page 11
Html page 12
Html page 13
HTML Forms and Input Fields
Html page 14
Html page 15
Html page 16
HTML Images and Media
Html page 17
Html page 18
HTML Links and Anchors
Html page 19
Html page 20
Html page 21
HTML Styles and Formatting
Html page 22
HTML Semantic Elements
Html page 23
Html page 24
HTML Attributes
Html page 25
Html page 26
HTML JavaScript Integration
Html page 27
Html page 28
Html page 29
Html page 30
HTML Document and Browser Support
Html page 31
Html page 32
HTML5 New Elements and Attributes
Html page 33
Html page 34
Html page 35
Html page 36
HTML Accessibility and Web Standards
Html page 37
Html page 38
Html page 39
HTML Responsive Design and Mobile Devices.
Html page 40
Html page 41
Html page 42
Introduction
Data Structure Page 1
Data Structure Page 2
Data Structure Page 3
Data Structure Page 4
Data Structure Page 5
Data Structure Page 6
Data Structure Page 7
Data Structure Page 8
String
Data Structure Page 9
Data Structure Page 10
Data Structure Page 11
Data Structure Page 12
Data Structure Page 13
Array
Data Structure Page 14
Data Structure Page 15
Data Structure Page 16
Data Structure Page 17
Data Structure Page 18
Linked List
Data Structure Page 19
Data Structure Page 20
Stack
Data Structure Page 21
Data Structure Page 22
Queue
Data Structure Page 23
Data Structure Page 24
Tree
Data Structure Page 25
Data Structure Page 26
Binary Tree
Data Structure Page 27
Data Structure Page 28
Heap
Data Structure Page 29
Data Structure Page 30
Graph
Data Structure Page 31
Data Structure Page 32
Searching Sorting
Data Structure Page 33
Hashing Collision
Data Structure Page 35
Data Structure Page 36
Go through our study material. Your Job is awaiting.