css网格

CSS | 网格容器 (CSS | Grid Containers)

There are numerous ways to display our list items or elements. For instance, we can display them in the navigation bar, in a menu bar and whatnot. Well, it would be right to say that there are many more such methods to imply to our web page. Besides, it is solely the developers' choice of what kind of styling or formatting they want to use for their list items. But let us discuss one such method which is used very often and also helps in making your web page much versatile and responsive, CSS Grid Container.

有很多方法可以显示我们的列表项或元素。 例如,我们可以在导航栏,菜单栏等中显示它们。 好吧,很正确地说,还有更多这样的方法暗示着我们的网页。 此外,这完全是开发人员选择要用于其列表项的样式或格式的选择。 但是,让我们讨论一种经常使用的方法,它还有助于使您的网页具有更多用途和响应能力,即CSS Grid Container

Grid container is not a tough method to use to display the elements of your web page. Well, what is the grid container is the first place? So, grid containers comprise of grid items and those same items are placed or inserted inside columns and rows. We all have come across various grids in our daily life, so imagine one such empty grid and start placing items inside that grid's rows and columns and there you are, that is a grid container and the same thing is possible in CSS as well.

网格容器并不是用来显示网页元素的艰难方法。 那么,什么是网格容器才是第一位的? 因此,网格容器由网格项目组成,并且将那些相同的项目放置或插入到​​列和行内。 我们每个人在日常生活中都遇到过各种各样的网格,所以想象一个空的网格并开始将项目放置在该网格的行和列中,然后就可以了,这是一个网格容器,并且CSS中也可以做到这一点。

Implementation:

实现方式:

With the definition of a grid container in mind, let us now understand how to make an element behave like a grid container. This again is not a tough task, all you gotta do is modify the display property a little bit. To make an element behave like a grid container, you will have to set your display property to grid or inline-grid. This way your HTML element will start behaving like a grid container.

考虑到网格容器的定义,让我们现在了解如何使元素表现得像网格容器一样。 再次这不是一项艰巨的任务,您要做的只是稍微修改一下显示属性。 为了使元素的行为像网格容器一样,您必须将display属性设置为grid或inline-grid 。 这样,您HTML元素将开始表现得像一个网格容器。

Syntax:

句法:

Element {display: grid/inline-grid;
}

Properties:

特性:

Now let us look at some of the grid container's properties:

现在让我们看一下网格容器的一些属性:

1)grid-template-columns属性 (1) The grid-template-columns property)

The fundamental use of grid-template-columns-property is to specify the total number of columns in the grid layout and it can also be used to specify the width of those columns.

grid-template-columns-property的基本用途是指定网格布局中的总列数,也可以用于指定这些列的宽度。

The values of this property are space-separated lists where each value would define the length of every column.

此属性的值是用空格分隔的列表,其中每个值将定义每列的长度。

For instance, if you wish to add 4 columns in your grid layout, just specify the width of the 4 columns or just type in auto for every column to have the same width.

例如,如果您希望在网格布局中添加4列,则只需指定4列的宽度,或者仅键入auto即可使每列具有相同的宽度。

Syntax:

句法:

Element {display: grid;
grid-template-columns: auto auto auto auto;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.grid {display: grid;
grid-template-columns: auto auto auto auto;
grid-gap: 15px;
background-color: red;
padding: 10px;
}
.grid> div {background-color: pink;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h1>CSS Grid container</h1>
</br>
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</body>
</html>

Output

输出量

Note: One thing to keep in mind here is that if you have more than 4 elements in a 4 column grid, then the grid will create a new row itself to fit in the items.

注意:这里要记住的一件事是,如果在4列网格中有4个以上的元素,则网格将自己创建一个新行以适合项目。

2)grid-template-rows属性 (2) The grid-template-rows property)

This property is the opposite of column property, in this, you can define the height of each row in the grid.

此属性与column属性相反,在此属性中,您可以定义网格中每一行的高度。

Syntax:

句法:

Element {grid-template-rows: 50px 100px;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.grid {display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: 80px 150px;
grid-gap: 10px;
background-color: red;
padding: 10px;
}
.grid > div {background-color: pink;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h1>CSS Grid container</h1>
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

Output

输出量

In the above example both rows are set by property grid-template-rows to 80px and 150px.

在上面的示例中,两行都通过属性grid-template-rows设置为80px和150px 。

3)证明内容属性 (3) The justify-content property)

To fit in the entire grid within the container justify-content property is used.

为了适合容器内的整个网格,使用了justify-content属性。

Syntax:

句法:

Element {justify-content: space-evenly;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.grid {display: grid;
justify-content: space-evenly;
grid-template-columns: 40px 60px 70px;
grid-gap: 10px;
background-color: pink;
padding: 10px;
}
.grid> div {background-color: red;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h1>CSS Grid container</h1>
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>

Output

输出量

Note: For this property to actually work, make sure that the grid's entire width should be less than that of the container's width.

注意:为了使此属性真正起作用,请确保网格的整个宽度应小于容器的宽度。

4)align-content属性 (4) The align-content property)

To align the entire grid vertically inside the container this property is used.

要在容器内垂直对齐整个网格,请使用此属性。

Syntax:

句法:

Element {align-content: center;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.grid {display: grid;
height: 400px;
align-content: center;
grid-gap: 15px;
grid-template-columns: auto auto auto;
background-color: pink;
padding: 10px;
}
.grid > div {background-color: red;
text-align: center;
padding: 20px 0;
font-size: 40px;
}
</style>
</head>
<body>
<h1>CSS Grid container</h1>
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>

Output

输出量

Note: For this property to actually work, make sure that the grid's entire height should be less than that of the container's height.

注意:要使此属性真正起作用,请确保网格的整个高度应小于容器的高度。

翻译自: https://www.includehelp.com/code-snippets/css-grid-container.aspx

css网格

css网格_CSS网格容器相关推荐

  1. css网格_CSS网格初学者指南

    css网格 by Kara Luton 卡拉·卢顿(Kara Luton) CSS网格初学者指南 (A Beginner's Guide to CSS Grid) I first heard abou ...

  2. css网格_CSS网格的逐步增强

    css网格 CSS Grid (Grid) has been out for some time now, with full support in major modern browsers. I' ...

  3. css 网格布局_CSS网格布局

    css 网格布局 网格布局 (Grid Layout) CSS Grid Layout, simply known as Grid, is a layout scheme that is the ne ...

  4. css响应式网格布局生成器_如何使用网格布局模块使用纯CSS创建响应表

    css响应式网格布局生成器 TL; DR (TL;DR) The most popular way to display a collection of similar data is to use ...

  5. CSS 学习笔记 - 网格布局(栅格系统)

    CSS 学习笔记 - 网格布局(栅格系统) 开启网格模式 基本概念 属性说明 容器属性 内容属性 效果展示 grid-template-rows.grid-template-columns 基本用法 ...

  6. 【第八篇】CSS布局之网格布局

    一个网页根据其各个功能块的分布,通常将其分成多个组成部分.同时为了页面美观,通常将各个功能模块放在页面固定的地方.CSS中存在多种布局方法,例如浮动,弹性和网格布局.每种布局都有其适用的范围. 网格布 ...

  7. css里面的网格布局

    那么首先来说说一下CSS 中 Grid 网格布局与 Grid 栅格系统的关系 CSS跟Grid布局没有半毛钱关系,Grid只不过是人们在遵循CSS规范的框架内摸索出来的一个最佳实践,你完全可以不鸟栅格 ...

  8. html5取消纵横比,CSS技巧:网格项目的纵横比

    之前,我们讲了纵横比方框,谈到一个技巧,就是运用填充来随心所欲地调整一个元素的长宽比例.这个技巧并不是经常能用到的,因为修整一个元素的高度是自找麻烦,但也不是没有这种情况出现. 要降低这一风险,有一种 ...

  9. css实现图片自适应容器的几种方式

    css实现图片自适应容器 经常有这样一个场景,需要让图片自适应容器的大小. 1.img标签的方式 我们马上就能想到,把width.height 设置为100%啊.来看一哈效果. <div cla ...

最新文章

  1. mysql 数据库编程_MySQL数据库编程(C++语言)
  2. java 不能反序列化_java中的序列化与反序列化
  3. 光耀卡服务器维修,3月28日服务器更新维护公告
  4. 阿里工程师用 8 张图告诉你如何存储、管理泛内容数据
  5. 【第一讲】APK应用程序的解包、修改、编辑、打包及应用(转)
  6. python 直方图均衡化_直方图均衡化-Python实现
  7. cocos creator 全局变量的几种方法
  8. 记忆宫殿--清华一日游
  9. vue.js的快速入门使用
  10. 判断用户是否已关注公众号
  11. 微信小程序实现:输入手机号点击按钮查询手机号归属地
  12. 【How2Pwn】DreamHack x64下的ROP问题
  13. 【001】基于JavaFX实现的电子图片管理系统
  14. echarts x轴数据旋转
  15. 实战 | 文件下载、及浏览器加速导致不能下载的问题
  16. 学界丨我这样预测了医疗AI的发展,或许你也可以(附论文链接)
  17. Activiti工作流引擎整合系列【收藏可做笔记系列】
  18. 激活函数relu、leaky-relu、elu、selu、serlu比较
  19. STM32F103学习记录-----GPIO篇
  20. Shell脚本:后台运行

热门文章

  1. 的优先级大小_如何评估需求的优先级?
  2. 信息系统项目管理师_信息系统项目管理师通过率是多少?
  3. 统计内存使用率shell
  4. 传百度无人车计划分拆,百度回复:不实信息,目前未有分拆计划
  5. 论文笔记:Person Re-identification with Deep Similarity-Guided Graph Neural Network
  6. SQL调用C# dll(第一中DLL,没使用强名称密匙,默认是 safe)
  7. [LeetCode] Longest Consecutive Sequence 求解
  8. 区别不同浏览器,CSS hack写法
  9. mysql表在线转成分区表_11g普通表在线转换分区表
  10. 乐学python_铁乐学python_day01-作业