css网格_CSS网格容器

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

输出量

CSS | Grid Container | Example 1

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

输出量

CSS | Grid Container | Example 2

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

输出量

CSS | Grid Container | Example 3

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

输出量

CSS | Grid Container | Example 4

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网格

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543805.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

c ++向量库_在C ++中对2D向量进行排序

c 向量库As per as a 2D vector is concerned its a vector of a 1D vector. But what we do in sorting a 1D vector like, 就2D向量而言&#xff0c;它是1D向量的向量 。 但是我们在对一维向量进行排序时所做的工作 sort(vector.begin(),vector.end());We cant do the same …

监听文本框数据修改,特别是微信等客户端直接选择粘贴修改

2019独角兽企业重金招聘Python工程师标准>>> // 手机号码信息加载验证 $(input).bind(input propertychange, function() { initPage.checkName(); }); 转载于:https://my.oschina.net/u/1579617/blog/550488

SSIA的完整形式是什么?

SSIA&#xff1a;主题说明一切 (SSIA: Subject Says It All) SSIA is an abbreviation of "Subject Says It All". SSIA是“主题说明一切”的缩写。 It is an expression, which is commonly used in the Gmail platform. It is written in the subject of the mail…

服务器控件转换成HTML

服务器控件转换成HTML<asp:Label ID"Label1" runat"server" Text"I am label"><asp:Literal ID"Literal1" runat"server" Text"I am a literal"><asp:Panel ID"Panel1" runat"serv…

Eratosthenes筛

什么是Eratosthenes筛&#xff1f; (What is Sieve of Eratosthenes?) Sieve of Eratosthenes is an ancient algorithm of finding prime numbers for any given range. Its actually about maintaining a Boolean table to check for corresponding prime no. Eratosthenes的…

微信iOS多设备多字体适配方案总结

一、背景 2014下半年&#xff0c;微信iOS版先后适配iPad, iPhone6/6plus。随着这些大屏设备的登场&#xff0c;部分用户觉得微信的字体太小&#xff0c;但也有很多用户不喜欢太大的字体。为了满足不同用户的需求&#xff0c;我们做了全局字体设置功能&#xff0c;在【设置-通用…

python矩阵中插入矩阵_Python | 矩阵的痕迹

python矩阵中插入矩阵The sum of diagonal elements of a matrix is commonly known as the trace of the matrix. It is mainly used in eigenvalues and other matrix applications. In this article, we are going to find the trace of a matrix using inbuilt function nu…

TOP命令监视系统任务及掩码umask的作用

top 命令使用方法及參数。 top 选择參数 參数&#xff1a; -b 以批量模式执行。但不能接受命令行输入&#xff1b;-c 显示命令行&#xff0c;而不不过命令名。-d N 显示两次刷新时间的间隔&#xff0c;比方 -d 5&#xff0c;表示两次刷新间隔为5秒&#xff1b;-i 禁止显示空暇…

python点线图_Python | 点线图

python点线图A mixture of dot and line plot is called a Dot-Line plot. Each dot is connected through a line and it is the next version of the line plot. It maintains the discrete property of the points and also represents the correlation between consecutive…

Android Studio导入工程的正确姿势

为什么80%的码农都做不了架构师&#xff1f;>>> 如果你有很好的网络环境 好的网络环境&#xff0c;这里不是指&#xff1a;我家网速带宽100M&#xff0c;电信的光纤接入。 而是&#xff1a;能翻墙。因为如果本机的gradle和将要导入的工程版本不匹配&#xff0c;Stu…

BBIAF的完整形式是什么?

BBIAF&#xff1a;回来几场 (BBIAF: Be Back In A Few) BBIAF is an abbreviation of "Be Back In A Few". BBIAF是“几回去”的缩写 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, …

为什么年轻人挣得很多还是穷?北上广深挑战指数报告~

又是年底&#xff0c;又到了做选择的时候。从“激情燃烧的岁月”到“何处安放的青春”&#xff0c;逃离北上广深的口号从未停止过&#xff0c;回到北上广深的呼喊更是一浪接着一浪。应届生们奔波忙碌&#xff0c;想有一份承载自己梦想的工作&#xff0c;想在异乡有一处安身之所…

apple组织名称是什么_什么是Apple Macintosh?

apple组织名称是什么苹果Macintosh (Apple Macintosh) Steve Jobs and Steve Wozniak has founded the line of computers in the year 1984, on the date 24th January, named it Apple Macintosh. Macintosh is shortly abbreviated as Mac. In this, various versions of co…

什么是Apple Desktop Bus? 亚行代表什么?

亚行&#xff1a;Apple桌面总线 (ADB: Apple Desktop Bus) ADB is an abbreviation of "Apple Desktop Bus". ADB是“ Apple Desktop Bus”的缩写 。 It is a low-speed proprietary bit-serial peripheral bus connecting devices to computers. In 1986, it was l…

CentOS 创建SVN 服务器,并且自动同步到WEB 目录

CentOS 创建SVN 服务器&#xff0c;并且自动同步到WEB 目录 标签&#xff1a; centossvnsubversion服务器2013-12-06 10:09 5492人阅读 评论(0) 收藏 举报分类&#xff1a;linux&#xff08;5&#xff09; 一、安装Subversion #yum install subversion二&#xff0c;基本的SVN服…

TTYL的完整形式是什么?

TTYL&#xff1a;稍后再与您交谈 (TTYL: Talk To You Later) TTYL is an abbreviation of Talk To You Later. It is an internet slang that is most generally used in text messaging, instant messaging, and chatting on Facebook, Twitter, WhatsApp, etc. The acronym i…

zhilizhili-ui 2016始动 开始做个样例站吧 (一)

对 我又挖坑了 不过其实也不算挖坑 因为ui构建中就会有填坑的文章 之前一直在写《编写大型web页面 结合现有前端形势思考未来前端》这是一篇巨难写的文章 估计要到年中才能写好了 写作的过程中 发生了国内前端大撕逼 2015的尾声大战 是否可以宣告前端是否开始新的时代 2016年 国…

python 网格_Python | 网格到情节

python 网格Most of the time, we need good accuracy in data visualization and a normal plot can be ambiguous. So, it is better to use a grid that allows us to locate the approximate value near the points in the plot. It helps in reducing the ambiguity and t…

2016年1月计划

开始试着每月做计划和总结&#xff0c;有节奏的规划自己的时间&#xff0c;一月计划&#xff1a; 1、hive那本书拖了很久了&#xff0c;一月一定会看完。 2、因为跟着阚爷的风准备试着做一下讲师&#xff0c;分配给我的是推荐这块&#xff0c;所以网上多找找做推荐的资源&#…

slr1文法_SLR的完整形式是什么?

slr1文法单反&#xff1a;单镜头反光 (SLR: Single Lens Reflex) SLR is an abbreviation of Single Lens Reflex. It is used in high standard cameras. SLR makes use of an automatic moving mirror arrangement that makes it possible for photographers to perceive pre…