当前位置: 首页 > 编程日记 > 正文

初学者css常见问题_5分钟内学习CSS Grid-初学者教程

初学者css常见问题

Grid layouts are fundamental to the design of websites, and the CSS Grid module is the most powerful and easiest tool for creating it. I personally think it’s a lot better than for example Bootstrap (read why here).

网格布局是网站设计的基础,而CSS网格模块是创建它的最强大,最简单的工具。 我个人认为它比Bootstrap好得多( 在这里阅读为什么)。

The module has also gotten native support by the major browsers (Safari, Chrome, Firefox, Edge), so I believe that all front-end developer will have to learn this technology in the not too distant future.

该模块还获得了主要浏览器 (Safari,Chrome,Firefox,Edge)的本地支持,因此我相信所有前端开发人员都必须在不远的将来学习该技术。

In this article, I'll take you through the very basics of CSS Grid as quickly as possible. I’ll be leaving out everything you shouldn’t care about until you’ve understood the basics.

在本文中,我将带您尽快了解CSS Grid的基础知识。 在您了解基本知识之前,我将遗漏您不关心的所有内容。

I’ve also created a free CSS Grid course. Click here to get full access toit.

我还创建了一个免费CSS Grid课程。 单击此处以获得对它的完整访问。

Alternatively, check out this article, which explains what you’ll learn throughout the course:

另外,请查看本文 ,其中介绍了您将在整个课程中学到的内容:

Now let’s jump into it!

现在开始吧!

您的第一个网格布局 (Your first grid layout)

The two core ingredients of a CSS Grid are the wrapper (parent) and theitems (children). The wrapper is the actual grid and the items are the content inside the grid.

CSS网格的两个核心要素是包装器 (父级)和项目 (子级)。 包装器是实际的网格,项目是网格内的内容。

Here’s the markup for a wrapper with six items in it:

这是其中包含六个项目的包装器的标记:

<div class="wrapper"><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div>
</div>

To turn our wrapper div into a grid, we simply give it a display ofgrid:

要将包装器div转换为网格 ,我们只需为其显示grid

But, this doesn’t do anything yet, as we haven’t defined how we want our grid to look like. It’ll simply stack 6 div'son top of each other.

但是,这还没有做任何事情,因为我们还没有定义我们希望网格的外观。 它将仅将6 div's堆叠在一起。

I’ve added a bit of styling, but that hasn’t got anything to do with CSS grid.

我添加了一些样式,但这与CSS网格没有任何关系。

列和行 (Columns and rows)

To make it two-dimensional, we’ll need to define the columns and rows.Let’s create three columns and two rows. We’ll use the grid-template-row and grid-template-column properties.

为了使其成为二维,我们需要定义列和行,让我们创建三列和两行。 我们将使用grid-template-rowgrid-template-column属性。

As we’ve written three values for grid-template-columns, we’ll get three columns. We’ll get two rows, as we’ve specified two values for the grid-template-rows.

当我们为grid-template-columns编写了三个值时,我们将获得三列。 我们将获得两行,因为我们为grid-template-rows指定了两个值。

The values dictate how wide we want our columns to be (100px) and how tall we’d want our rows to be (50px). Here’s the result:

这些值指示我们希望列的宽度为(100px),我们希望行的高度为(50px)。 结果如下:

To make sure you properly understand the relation between the values and how the grid looks, take a look at this example as well.

为了确保您正确理解值之间的关系以及网格的外观,还请看一下此示例。

.wrapper {display: grid;grid-template-columns: 200px 50px 100px;grid-template-rows: 50px 50px;
}

Try to grasp the connection between the code and the layout.

尝试掌握代码和布局之间的联系。

Here’s how it plays out:

播放方法如下:

放置物品 (Placing the items)

The next thing you’ll need to learn is how to place items on the grid. This is where you get superpowers, as it makes it dead simple to create layouts.

您需要学习的下一件事是如何将项目放置在网格上。 这是您获得超能力的地方,因为它使创建布局变得非常简单。

Let’s create a 3x3 grid, using the same markup as before.

让我们使用与以前相同的标记创建一个3x3网格。

.wrapper {display: grid;grid-template-columns: 100px 100px 100px;grid-template-rows: 100px 100px 100px;
}

This will result in the following layout:

这将导致以下布局:

Notice, we only see a 3x2 grid on the page, while we defined it as a 3x3 grid. That’s because we only have six items to fill the grid with. If we had three more, then the lowest row would be filled as well.

注意,我们在页面上仅看到3x2网格,而我们将其定义为3x3网格。 这是因为我们只有六个项目可用于填充网格。 如果再增加三个,则最低行也将被填充。

To position and resize the items we’ll target them and use the grid-column and grid-row properties:

要定位和调整项目的大小,我们将它们定位为目标,并使用grid-columngrid-row属性:

.item1 {grid-column-start: 1;grid-column-end: 4;
}

What we’re saying here is that we want item1 to start on the first grid line and end on the fourth column line. In other words, it’ll take up the entire row.

我们在这里说的是,我们希望item1从第一条网格线开始,到第四列线结束。 换句话说,它将占用整行。

Here’s how that’ll play out on the screen:

这是在屏幕上显示的方式:

Are you confused why we have 4 column lines when we only have 3 columns? Take a look at this image, where I’ve drawn the column lines in black:

您是否感到困惑,为什么只有3列却有4列? 看一下这张图片,我在其中绘制了黑色的列线:

Notice that we’re now using all the rows in the grid. When we made the first item take up the entire first row, it pushed the rest of the items down.

注意,我们现在正在使用网格中的所有行。 当我们使第一个项目占据整个第一行时,它会将其余项目推下。

Finally, I’d like to show a simpler way of writing the syntax above:

最后,我想展示一种编写上述语法的简单方法:

To make sure you’ve understood this concept properly, let’s rearrange the items a little bit.

为了确保您正确理解了这个概念,让我们重新排列一下项目。

.item1 {grid-column-start: 1;grid-column-end: 3;
}.item3 {grid-row-start: 2;grid-row-end: 4;
}.item4 {grid-column-start: 2;grid-column-end: 4;
}

Here’s how that looks on the page. Try to wrap your head around why it looks like it does. It shouldn’t be too hard.

这是页面上的外观。 试着绕着为什么看起来像这样。 应该不难。

And that was it!

就是这样!



Thanks for reading! My name is Per Borgen, I'm the co-founder of Scrimba – the easiest way to learn to code. You should check out our responsive web design bootcamp if want to learn to build modern website on a professional level.

谢谢阅读! 我叫Per Borgen,我是Scrimba的共同创始人–学习编码的最简单方法。 如果要学习以专业水平构建现代网站,则应查看我们的响应式Web设计新手训练营 。

翻译自: https://www.freecodecamp.org/news/learn-css-grid-in-5-minutes-f582e87b1228/

初学者css常见问题

相关文章:

HBase保存的各个字段意义解释

// Author&#xff1a;xxx0624 HomePage&#xff1a;http://www.cnblogs.com/xxx0624/ // nutch2.2.1集成HBase0.94.25, 可以查询nutch的conf文件中的gora-hbase-mapping.xml查看原文件 <gora-orm><table name"webpage"><family name"p" ma…

AJAX基础篇

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 正文&#xff1a; 整理一下AJAX相关的知识&#xff0c;帮助自己复习的同时希望还能够帮助到新加入前端阵营的小伙伴们。 1.AJAX是什么&#xff1f; AJAX 异步的JavaScript和XML 2.AJAX的作用&…

在运筹学中什么样的解决方案是最优的

问题: 1.在运筹学中什么样的解决方案是最优的 2.线性代数解决的是什么问题? 3.运筹学与线性代数的关系? 4.如何使用matlab 解决运筹学中的问题? 转载于:https://www.cnblogs.com/lwy1103/p/6676373.html

npm构建脚本_NPM脚本简介

npm构建脚本by Mohammed Ajmal Siddiqui由Mohammed Ajmal Siddiqui NPM脚本简介 (Introduction to NPM Scripts) NPM scripts are among my favorite features of NPM. They are simple. They reduce the need for tools. Hence they reduce the number of configuration file…

SQL 中循环、for循环、游标

我们使用SQL语句处理数据时&#xff0c;可能会碰到一些需要循环遍历某个表并对其进行相应的操作&#xff08;添加、修改、删除&#xff09;&#xff0c;这时我们就需要用到咱们在编程中常常用的for或foreach&#xff0c;但是在SQL中写循环往往显得那么吃力&#xff0c;翻遍网上…

Unix Linux大学教程(三):过滤器、正则表达式、vi

第16章 过滤器&#xff1a;简介和基本操作 删除数据列用colrm&#xff1a;colrm [startcol [endcol]] 如果没有endcol则删除从startcol至行末尾所有的列。 第17章 过滤器&#xff1a;比较和抽取 比较任意两个文件&#xff1a;cmp file1 file2 显示不同字节数及所在行。 比…

微信小程序获取多选框选中值和选中值对应的id

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 官方文档中只有获取多选框的值的方法&#xff0c;但是我需要获取选中的值同时还要获取选中值对应的id&#xff0c;但是又不能操作DOM获取&#xff0c;相信和我有同样需求的伙伴们都会为此发愁&#xff0…

调试代码遗留_陷入遗留代码地狱吗? 这里有一些想法可以帮助您处理情况

调试代码遗留by Felipe Lopes通过Felipe Lopes 陷入遗留代码地狱吗&#xff1f; 这里有一些想法可以帮助您处理情况 (Stuck in legacy code hell? Here are some few thoughts to help you manage the situation) I’m gonna tell you a little story about how I ended up i…

求二维数组最大子数组

结对队友&#xff1a;胡康臻、杨寒寒 1、设计思想&#xff1a; 首先定义产生二维数组&#xff0c;定义可输入二维数组行和列&#xff0c;各位数随机产生&#xff1b; 然后进行最大子数组的求和比较&#xff0c;从每行的第一个数为子数组的起点开始进行不同的子数组遍历比较&…

UVa 11021 (概率 递推) Tribles

Tribble是麻球&#xff1f; 因为事件都是互相独立的&#xff0c;所以只考虑一只麻球。 设f(i)表示一只麻球i天后它以及后代全部死亡的概率&#xff0c;根据全概率公式&#xff1a; f(i) P0 P1 * f(i-1) P2 * f(i-1)2 ... Pn * f(n)n 每个麻球死亡是独立的&#xff0c;所以…

积分页面布局记录

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 、 // pages/user/my_integral/record/record.js var app getApp(); var util require("../../../utils/util.js") Page({data: {url_data: ,username: ,usertop: ,tab: 1…

uber_Uber是如何制成的

uberby Dmytro Brovkin由Dmytro Brovkin Uber是如何制成的 (How Uber was made) Uber has transformed the world. Indeed, its inconceivable to think of a world without the convenience of the innovative ride sharing service. Tracing its origins in a market which …

HTML 标签包含规范,规避脱标流,图片和文字垂直居中对齐,

&#xff11; 标签包含规范 ◆div可以包含所有的标签。 ◆p标签不能包含div h1等标签。 ◆h1可以包含p&#xff0c;div等标签。 ◆行内元素尽量包含行内元素&#xff0c;行内元素不要包含块元素。 2 规避脱标流 ◆尽量使用标准流。 ◆标准流解决不了的使用浮动。 ◆浮动解决不了…

Java Socket发送与接收HTTP消息简单实现

在上次Java Socket现实简单的HTTP服务我 们实现了简单的HTTP服务&#xff0c;它可以用来模拟HTTP服务&#xff0c;用它可以截获HTTP请求的原始码流&#xff0c;让我们很清楚的了解到我们向服务发的HTTP消息的结 构&#xff0c;对HTTP请求消息有个清晰的认识。这一节我想写了一个…

微信小程序日期相减得出天数

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; // 日期结算 num_data: function (e) {var start_date new Date(this.data.start_date.replace(/-/g, "/"));var end_date new Date(this.data.end_date.replace(/-/g, &q…

es6 ... 添加属性_如何在10分钟内免费将HTTPS添加到您的网站,以及为什么您现在不止需要这样做......

es6 ... 添加属性by Ayo Isaiah通过Ayo Isaiah 如何在10分钟内免费将HTTPS添加到您的网站&#xff0c;以及为什么现在比以往更需要这样做 (How to add HTTPS to your website for free in 10 minutes, and why you need to do this now more than ever) Last week, Google ann…

程序员跳槽全攻略——读书笔记

有同学说&#xff0c;我技术很好啊&#xff0c;又会机器学习又会编译原理&#xff0c;凭什么那些写Javascript的薪水比我高一倍&#xff1f; 谁让你在一家建站公司上班呢。对一家做网站的公司而言&#xff0c;机器学习和编译原理是不能为它带来收益的&#xff0c;而Javascript写…

[转] Gradle: 此时不应有 Androidandroid-studiosdk oolslib\find_java.exe。解决方法

上述问题主要是java路径的问题&#xff0c;这里主要给出解决方案&#xff0c;至于为什么这么解决的&#xff0c;大家可以学学bat语言。想问的可以留言我。 dx.bat 根据安装目录&#xff0c;我的是D:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.2.2…

微信小程序和微信小程序之间的跳转和传参示例代码附讲解

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 一&#xff1a;微信小程序跳转 使用限制 需要用户触发跳转 从 2.3.0 版本开始&#xff0c;若用户未点击小程序页面任意位置&#xff0c;则开发者将无法调用此接口自动跳转至其他小…

电子界卡组构建2019_2018–2019年构建现代Android应用程序的路线图

电子界卡组构建2019Kriptofolio应用程序系列—简介 (Kriptofolio app series — Introduction) Welcome to this series of blog posts where I will be creating a modern Android app. I will use the best tools and practices available in the year 2018–2019. I am doin…

python操作mysql数据库实现增删改查

Python 标准数据库接口为 Python DB-API&#xff0c;Python DB-API为开发人员提供了数据库应用编程接口。 Python 数据库接口支持非常多的数据库&#xff0c;你可以选择适合你项目的数据库&#xff1a; GadFlymSQLMySQLPostgreSQLMicrosoft SQL Server 2000InformixInterbaseOr…

弹性布局,自动按比例居中

1. 让行类盒子及盒子的元素 自动按比例居中效果图 html <view classaaa><view classbbb>aaaaaaaaa</view><view classbbb>aaaaaaaaa</view><view classbbb>bb</view><view classbbb>aaaaaaaaa</view> </view> c…

Ubuntu 14.04系统托盘图标问题,skype托盘图标显示

Ubuntu 14.04系统托盘图标问题&#xff0c;skype托盘图标显示_瑞波支付_新浪博客 Ubuntu 14.04 取消了系统托盘白名单机制&#xff0c;导致使用传统系统托盘技术的程序无法显示出托盘图标,dconf-editor也无力解决这个问题 。Ubuntu Unity桌面目前使用的技术是indicator-applica…

以太坊去中心化_开发以太坊去中心化投票应用程序的指南

以太坊去中心化by Timothy Ko蒂莫西高(Timothy Ko) 开发以太坊去中心化投票应用程序的指南 (A guide to developing an Ethereum decentralized voting application) After the entire cryptocurrency market passed 700 billion dollars in market cap, the cryptocurrency s…

Intellij IDEA的下载和使用(针对学生的免费使用计划)

一、下载和使用授权&#xff08;针对学生&#xff09; 1、下载 可以在Intellij IDEA官网上下载需要的版本。下载地址&#xff1a;https://www.jetbrains.com/idea/ 2、学生免费试用 首先&#xff0c;你得现有你们学校的官方邮箱账户&#xff0c;例如XXXYYY.edu.cn 其次&#xf…

LPC1768基本输入输出GPIO使用

LPC1788通用IO口的控制包含了一些基本的组件,比如设置推挽输出,开漏输出,上拉电阻等,我们今天来看看. 首先使用GPIO要打开GPIO的系统时钟 LPC_SC->PCONP | (1<<15);//gpio 时钟 然后需要选择我们选定引脚的功能,有些引脚有多个功能,通过寄存器可以从中选择一个 之后是…

微信小程序发红包功能实现,附效果图加讲解。

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 需要做红包功能的可以找我&#xff0c;收费卖源码&#xff0c;也承接开发。此博文仅示例。 流程效果图&#xff1a; 图片1触发wx.sendBizRedPacket({})吊起图片2&#xff0c;点击开&#xff0c;出现图…

项目部署时网关怎么回事_使用Kubernetes部署聊天网关(或技术按预期运行时)...

项目部署时网关怎么回事by Richard Li理查德李(Richard Li) 使用Kubernetes部署聊天网关(或技术按预期运行时) (Using Kubernetes to deploy a chat gateway (or when technology works like it’s supposed to)) TL; DR (TL;DR) This is a story about what happens when clo…

如何用php实现分页效果

分页效果在网页中是常见的&#xff0c;可是怎样才能实现分页呢&#xff0c;今天做了两种方法来实现一下分页的效果 首先&#xff0c;我们需要准备在数据库里面准备一个表&#xff0c;并且插入数据&#xff0c;这些都是必需的前提工作了&#xff0c;不多说&#xff0c;如图所示&…

微信小程序在showToast中换行并且隐藏icon

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 实现代码&#xff1a; 注释&#xff1a;真机才有效果&#xff0c;开发工具展示icon属性无效 var a 11\r\n3wx.showToast({title: a,icon:none,duration: 5000})