登录  /  注册
博主信息
博文 128
粉丝 9
评论 5
访问量 233898
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
【布局】教你用Grid网格布局详细教程入门笔记+实战案例
 一纸荒凉* Armani
原创
2081人浏览过

Grid 网格布局介绍

CSS 网格布局擅长于将一个页面划分为几个主要区域,以及定义这些区域的大小、位置、层次等关系(前提是HTML生成了这些区域)。

像表格一样,网格布局让我们能够按行或列来对齐元素。 然而在布局上,网格比表格更可能做到或更简单。 例如,网格容器的子元素可以自己定位,以便它们像CSS定位的元素一样,真正的有重叠和层次。

img

上图这样的布局,就是 Grid 布局的拿手好戏。

Grid 布局与 Flex 布局有一定的相似性,都可以指定容器内部多个项目的位置。但是,它们也存在重大区别。

Flex 布局是轴线布局,只能指定”项目”针对轴线的位置,可以看作是一维布局。Grid 布局则是将容器划分成”行”和”列”,产生单元格,然后指定”项目所在”的单元格,可以看作是二维布局。Grid 布局远比 Flex 布局强大。

MDN 网格布局 参考网址

常用属性

序号 属性 描述
1 grid-template-columns 定义网格轨道中的列宽
2 grid-template-rows 定义网格轨道中的行高
3 gap 网格轨道间距
4 grid-auto-flow 项目在容器中的排列方向
5 grid-auto-rows 隐式网格单元的行高
6 grid-auto-columns 隐式网格单元的列宽
7 grid-area 定义网格区域
8 place-items 所有项目在网络单元中的对齐方式
9 place-self 某个项目在网络单元(含网格区域)中的对齐方式
10 place-content 项目在网格容器中的对齐方式

常用术语

序号 术语 描述
1 网格容器 dispaly:grid属性定义的元素
2 网格项目 网格容器的直接子元素
3 网格区域 由一个或多个单元格组成的矩形区域
4 网格轨道 有行轨道与列轨道之分
5 轨道间距 分为行轨间隙和列轨间隙

  1. 圣怀布局:
    grid实现,二边固定,中间自适应,主体优先渲染
  2. 网格容器:
    由若干个矩形网格单元构成
  3. 网格项目:
    网格容器的子元素,必须放在网格单元中
  4. 网格单元:
    有”单元格”和”网格区域”二种表现形式
  5. 网格轨道:
    由多个网格单元组成,根据排列方向有”行轨”和”列轨”之分
  6. 轨道间距:
    容器中轨道之间的间距,有”行轨间距”和”列轨间距”
  7. fr:
    网格的伸缩因子
  8. repeat:
    文本重写的函数(以空格分隔)
  9. minmax:
    最小到最大区间的函数

grid快速实现”圣怀布局 代码

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>grid快速实现"圣怀布局"</title>
  8. <style>
  9. /* 圣怀布局:grid实现,二边固定,中间自适应,主体优先渲染 */
  10. body * {
  11. border: 1px solid #000;
  12. }
  13. body {
  14. display: grid;
  15. grid-template-columns: 15em minmax(50vw,auto) 15em;
  16. grid-template-rows: 3em minmax(80vh,auto) 3em;
  17. gap: 0.5em;
  18. }
  19. header,footer {
  20. grid-area: span 1 / span 3;
  21. }
  22. main {
  23. grid-area: 2 /2;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <!-- 圣怀布局要求主体区优先显示,根据浏览器渲染顺序,主体应该写到前面去。 -->
  29. <header>header</header>
  30. <!-- 主体main应该优先渲染 -->
  31. <main>main</main>
  32. <aside class="left">left</aside>
  33. <aside class="right">right</aside>
  34. <footer>footer</footer>
  35. </body>
  36. </html>


容器属性

grid-template-columns 属性 grid-template-rows 属性

容器指定了网格布局以后,接着就要划分行和列。
grid-template-columns属性定义每一列的列宽
grid-template-rows属性定义每一行的行高。

指定三行三列的网格,列宽和行高都是100px

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>grid网格布局</title>
  7. <style>
  8. .container {
  9. display: grid;
  10. grid-template-columns: 100px 100px 100px;
  11. grid-template-rows: 100px 100px 100px;
  12. /* 除了使用绝对单位,也可以使用百分比 */
  13. /* grid-template-columns: 33.33% 33.33% 33.33%;
  14. grid-template-rows: 33.33% 33.33% 33.33%; */
  15. }
  16. .container .item {
  17. font-size: 60px;
  18. text-align: center;
  19. background-color: pink;
  20. }
  21. .container .item:nth-child(even) {
  22. background-color: green;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div class="container">
  28. <div class="item">1</div>
  29. <div class="item">2</div>
  30. <div class="item">3</div>
  31. <div class="item">4</div>
  32. <div class="item">5</div>
  33. <div class="item">6</div>
  34. <div class="item">7</div>
  35. <div class="item">8</div>
  36. <div class="item">9</div>
  37. </div>
  38. </body>
  39. </html>


gap设置网格轨道间隙

  1. .container {
  2. display: grid;
  3. grid-template-columns: 100px 100px 100px;
  4. grid-template-rows: 100px 100px 100px;
  5. /* gap: 水平间隙(行) 垂直间隙(列) */
  6. gap: 10px 20px;
  7. }


grid-auto-flow 排列方向

划分网格以后,容器的子元素会按照顺序,自动放置在每一个网格。默认的放置顺序是”先行后列”,即先填满第一行,再开始放入第二行

  1. .container {
  2. display: grid;
  3. grid-template-columns: repeat(3, 150px);
  4. grid-template-rows: repeat(3, 150px);
  5. gap: 1px;
  6. /* 项目在容器中的排列方向 */
  7. grid-auto-flow: column
  8. }

这个顺序由grid-auto-flow属性决定,默认值是row,即”先行后列”。也可以将它设成column,变成”先列后行”


grid-auto-columns 属性, grid-auto-rows 属性

有时候,一些项目的指定位置,在现有网格的外部。比如网格只有3列,但是某一个项目指定在第5行。这时,浏览器会自动生成多余的网格,以便放置项目。
grid-auto-columns属性和grid-auto-rows属性用来设置,浏览器自动创建的多余网格的列宽和行高。它们的写法与grid-template-columnsgrid-template-rows完全相同。如果不指定这两个属性,浏览器完全根据单元格内容的大小,决定新增网格的列宽和行高。

划分好的网格是3行 x 3列,但是,8号项目指定在第4行,9号项目指定在第5行。

  1. .container {
  2. display: grid;
  3. grid-template-columns: 100px 100px 100px;
  4. grid-template-rows: 100px 100px 100px;
  5. grid-auto-rows: 50px;
  6. }

指定新增的行高统一为50px(原始的行高为100px)


grid-template-areas 定义区域

网格布局允许指定”区域”(area),一个区域由单个或多个单元格组成。grid-template-areas属性用于定义区域。

  1. .container {
  2. display: grid;
  3. grid-template-columns: 100px 100px 100px;
  4. grid-template-rows: 100px 100px 100px;
  5. grid-template-areas: 'a b c' 'd e f' 'g h i';
  6. }


先划分出9个单元格,然后将其定名为ai的九个区域,分别对应这九个单元格。

多个单元格合并成一个区域的写法如下。将9个单元格分成abc三个区域

  1. grid-template-areas: 'a a a'
  2. 'b b b'
  3. 'c c c';

下面是一个布局实例圣杯布局

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>圣杯布局</title>
  7. <style>
  8. body * {
  9. border: 1px solid #000;
  10. }
  11. body {
  12. display: grid;
  13. grid-template-columns: 15em minmax(50vw, auto) 15em;
  14. grid-template-rows: 3em minmax(80vh, auto) 3em;
  15. place-content: center;
  16. gap: 0.5em;
  17. grid-template-areas: "header header header"
  18. "left main right"
  19. "footer footer footer";
  20. }
  21. /* header,
  22. footer {
  23. grid-area: span 1 / span 3;
  24. }
  25. main {
  26. grid-area: 2 /2;
  27. } */
  28. /* 等同于 */
  29. header {
  30. grid-area: header;
  31. }
  32. footer {
  33. grid-area: footer;
  34. }
  35. main {
  36. grid-area: main;
  37. }
  38. aside.left{
  39. grid-area: left;
  40. }
  41. aside.right{
  42. grid-area: right;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <header>header</header>
  48. <main>main</main>
  49. <aside class="left">left</aside>
  50. <aside class="right">right</aside>
  51. <footer>footer</footer>
  52. </body>
  53. </html>


顶部是页眉区域header,底部是页脚区域footer,中间部分则为leftmainright

如果某些区域不需要利用,则使用”点”(.)表示

  1. grid-template-areas: 'a . c'
  2. 'd . f'
  3. 'g . i';

中间一列为点,表示没有用到该单元格,或者该单元格不属于任何区域。


place-items属性

设置单元格内容的水平位置(左中右)垂直位置(上中下)

  1. .container {
  2. /* 如果省略第二个值,则浏览器认为与第一个值相等 */
  3. /* 垂直对齐方式 水平对齐方式 */
  4. place-items: start end;
  5. }
  • start:对齐单元格的起始边缘。
  • end:对齐单元格的结束边缘。
  • center:单元格内部居中。
  • stretch:拉伸,占满单元格的整个宽度(默认值)。

    注意:项目默认是拉伸的,如果设置了大小,并小于单元空间的话
    在单元格中就会存在剩余空间可以被分配,这时对齐就有意义了。

  1. .container {
  2. display: grid;
  3. grid-template-columns: repeat(3, 150px);
  4. grid-template-rows: repeat(2, 150px);
  5. gap: 1px;
  6. grid-auto-flow: row;
  7. grid-auto-rows: 200px;
  8. /* 单元格内容对齐方式 */
  9. place-items: end center;
  10. }
  11. .item{
  12. font-size: 30px;
  13. text-align: center;
  14. background-color: pink;
  15. width: 60px;
  16. height: 60px;
  17. }


place-content 属性

整个内容区域在容器里面的水平位置(左中右),垂直位置(上中下)

  1. place-content: space-around space-evenly;
  • start - 对齐容器的起始边框。
  • end - 对齐容器的结束边框。
  • center - 容器内部居中。
  • stretch - 项目大小没有指定时,拉伸占据整个网格容器。
  • space-around - 每个项目两侧的间隔相等。所以,项目之间的间隔比项目与容器边框的间隔大一倍。
  • space-between - 项目与项目的间隔相等,项目与容器边框之间没有间隔。
  • space-evenly - 项目与项目的间隔相等,项目与容器边框之间也是同样长度的间隔。
  1. .container {
  2. width: 600px;
  3. height: 600px;
  4. display: grid;
  5. grid-template-columns: repeat(3, 150px);
  6. grid-template-rows: repeat(2, 150px);
  7. gap: 1px;
  8. grid-auto-flow: row;
  9. grid-auto-rows: 200px;
  10. /* 单元格内容对齐方式 */
  11. place-items: end center;
  12. /* 整个内容区域在容器里面对齐方式 */
  13. place-content: center center;
  14. }


项目属性

grid-area 属性

grid-area属性指定项目放在哪一个区域
项目的位置是可以指定的,具体方法就是指定项目的四个边框,分别定位在哪根网格线。
四个值分别是:

  • grid-row-start属性:上边框所在的水平网格线
  • grid-column-start属性:左边框所在的垂直网格线
  • grid-row-end属性:下边框所在的水平网格线
  • grid-column-end属性:右边框所在的垂直网格线
  1. .item-1 {
  2. grid-area: e;
  3. /* 行起始编号 / 列起始编号 / 行结束编号 / 列结束编号 */
  4. grid-area: 1 / 1 / 3 / 3;
  5. /* 结束行列编号可以省略,默认跨越1行1列 */
  6. grid-area: 1 / 1;
  7. /* 例如跨越两行三列 */
  8. grid-area: 1 / 1 / 3 / 4;
  9. /* 还可以使用`span`关键字,表示"跨越",即左右边框(上下边框)之间跨越多少个网格 */
  10. /* 通常不关心结束位置,我们只想要知道跨越几行几列 */
  11. grid-area: 1 / 1 / span 2 / span 3;
  12. }

place-self属性

  1. place-self: center center;
  • start:对齐单元格的起始边缘。
  • end:对齐单元格的结束边缘。
  • center:单元格内部居中。
  • stretch:拉伸,占满单元格的整个宽度(默认值)。
    place-items属性的用法完全一致,但只作用于单个项目
    1. .container .item:nth-child(5){
    2. place-self: center;
    3. }


repeat()函数

有时候,重复写同样的值非常麻烦,尤其网格很多时。这时,可以使用repeat()函数,简化重复的值。上面的代码用repeat()改写如下。

  1. .container {
  2. display: grid;
  3. grid-template-columns: repeat(3, 33.33%);
  4. grid-template-rows: repeat(3, 33.33%);
  5. }

repeat()接受两个参数,第一个参数是重复的次数(上例是3),第二个参数是所要重复的值。
repeat()重复某种模式也是可以的。

  1. grid-template-columns: repeat(2, 100px 20px 80px);

定义了6列,第一列和第四列的宽度为100px,第二列和第五列为20px,第三列和第六列为80px

fr 关键字

为了方便表示比例关系,网格布局提供了fr关键字(fraction 的缩写,意为”片段”)。如果两列的宽度分别为1fr2fr,就表示后者是前者的两倍。

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

  1. .container {
  2. display: grid;
  3. grid-template-columns: repeat(3,1fr);
  4. grid-template-rows: repeat(3,1fr);
  5. }

fr可以与绝对长度的单位结合使用,这时会非常方便。

  1. .container {
  2. display: grid;
  3. grid-template-columns: 150px 1fr 2fr;
  4. grid-template-rows: repeat(3, 1fr);
  5. gap: 1px;
  6. }

表示,第一列的宽度为150像素,第二列的宽度是第三列的一半。

  1. .container {
  2. /* 转为网格容器进行布局 */
  3. display: grid;
  4. border: 1px solid #000;
  5. padding: 0.5em;
  6. /* 1. 设置轨道的列宽 */
  7. /* grid-template-columns: auto auto auto; */
  8. /* 要求,第二列是第一列和第三的宽度的2倍,这个功能用auto是无法实现 */
  9. /* grid-template-columns: 1fr 3fr 1fr; */
  10. /* grid-template-columns: 25% 50% 25%; */
  11. /* grid-template-columns: 20% 60% 20%; */
  12. grid-template-columns: 8em 1fr 2fr 100px;
  13. /* 先计算出固定的值: 8*16 + 100 = ? */
  14. /* 总宽度 - 已知的固定宽度(8*16 + 100) = 100% */
  15. /* 第2列,分到1/3, 第3列分到2/3 */
  16. /* 2. 设置田轨道的行高 */
  17. grid-template-rows: 5em 5em;
  18. /* 3. 设置轨道间的间隙 */
  19. gap: 0.5em;
  20. }

auto-fill 关键字

有时,单元格的大小是固定的,但是容器的大小不确定。如果希望每一行(或每一列)容纳尽可能多的单元格,这时可以使用auto-fill关键字表示自动填充。

  1. .container {
  2. display: grid;
  3. grid-template-columns: repeat(*auto-fill*, 100px);
  4. }

表示每列宽度100px,然后自动填充,直到容器不能放置更多的列。

minmax()函数

产生一个长度范围,表示长度就在这个范围之中。它接受两个参数,分别为最小值和最大值。

minmax(100px, 1fr)表示中间的列宽不小于100px,不大于1fr

auto 关键字

auto关键字表示由浏览器自己决定长度。

  1. grid-template-columns: 100px auto 100px;

第二列的宽度,基本上等于该列单元格的最大宽度,除非单元格内容设置了min-width,且这个值大于最大宽度。

  1. grid-template-columns: auto auto auto;

三列平均分配占满浏览器

  1. .container {
  2. /* 转为网格容器进行布局 */
  3. display: grid;
  4. border: 1px solid #000;
  5. padding: 0.5em;
  6. /* 1. 设置轨道的列宽 */
  7. /* grid-template-columns: 10em 10em 10em; */
  8. /* 1. repeat() */
  9. /* grid-template-columns: repeat(3, 10em); */
  10. /* 第二个参数支持多个值 */
  11. /* grid-template-columns: repeat(3, 10em 2em);
  12. grid-template-columns: 10em 2em 10em 2em 10em 2em; */
  13. /* grid-template-columns: repeat(3, 1fr); */
  14. /* 2. minmax() */
  15. /* grid-template-columns: 1fr 2fr 1fr; */
  16. /* 第二个设置一个最小值 */
  17. grid-template-columns: 1fr minmax(20em, 2fr) 1fr;
  18. /* 2. 设置田轨道的行高 */
  19. grid-template-rows: 5em 5em;
  20. /* 3. 设置轨道间的间隙 */
  21. gap: 0.5em;
  22. }

网格容器/网格项目/网格单元/网格轨道/轨道间距

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>网格容器/网格项目/网格单元/网格轨道/轨道间距</title>
  8. <style>
  9. /* 1.网格容器:由若干个矩形网格单元构成
  10. 2.网格项目:网格容器的子元素,必须放在网格单元中
  11. 3.网格单元:有"单元格"和"网格区域"二种表现形式
  12. 4.网格轨道:由多个网格单元组成,根据排列方向有"行轨"和"列轨"之分
  13. 5.轨道间距:容器中轨道之间的间距,有"行轨间距"和"列轨间距" */
  14. /* 网格容器 */
  15. .container {
  16. border: 1px solid #000;
  17. padding: 0.5em;
  18. /* flex中子元素默认为行内(inline)元素,grid中子元素默认为块(block)元素 */
  19. display: grid;
  20. /* 1.设置轨道的列宽 */
  21. /* 设置一个3列2行的布局空间 */
  22. grid-template-columns: auto;
  23. grid-template-columns: 10em 10em 10em;
  24. /* 2.设置轨道的行高 */
  25. grid-template-rows: auto;
  26. grid-template-rows: 5em 5em;
  27. /* 3.设置轨道的间距 */
  28. /* gap: 水平 垂直 */
  29. gap: 0.5em 1em;
  30. gap: 0.5em 0.5em;
  31. /* gap: 0.5em 0.5em;可简写gap: 0.5em; */
  32. gap: 0.5em;
  33. }
  34. /* 网格项目:网格容器中的"子元素"(不能是孙元素),与flex是一样的 */
  35. .container>.item {
  36. /* 默认生成一列N行的容器(N就是项目的数量) */
  37. background-color: pink;
  38. border: 1px solid #000;
  39. padding: 0.5em;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="container">
  45. <span class="item">item1</span>
  46. <span class="item">item2</span>
  47. <span class="item">item3</span>
  48. <span class="item">item4</span>
  49. <span class="item">item5</span>
  50. <span class="item">item6</span>
  51. </div>
  52. </body>
  53. </html>

模拟bootstrap中的12列栅格布局组件

  1. /* 初始化 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. body {
  8. width: 100vw;
  9. height: 100vh;
  10. display: grid;
  11. place-content: center;
  12. }
  13. .container {
  14. min-width: 80vw;
  15. display: grid;
  16. gap: 0.5em;
  17. }
  18. .container > .row {
  19. display: grid;
  20. grid-template-columns: repeat(12,1fr);
  21. min-height: 3em;
  22. gap: 0.5em;
  23. }
  24. .container > .row >.item{
  25. background: lightcyan;
  26. padding: 1em;
  27. text-align: center;
  28. /* background-color: lightcyan; */
  29. border: 1px solid;
  30. /* border-radius: 5px; */
  31. }
  32. .col-12 {
  33. grid-area: auto / span 12;
  34. }
  35. .col-11 {
  36. grid-area: auto / span 11;
  37. }
  38. .col-10 {
  39. grid-area: auto / span 10;
  40. }
  41. .col-9 {
  42. grid-area: auto / span 9;
  43. }
  44. .col-8 {
  45. grid-area: auto / span 8;
  46. }
  47. .col-7 {
  48. grid-area: auto / span 7;
  49. }
  50. .col-6 {
  51. grid-area: auto / span 6;
  52. }
  53. .col-5 {
  54. grid-area: auto / span 5;
  55. }
  56. .col-4 {
  57. grid-area: auto / span 4;
  58. }
  59. .col-3 {
  60. grid-area: auto / span 3;
  61. }
  62. .col-2 {
  63. grid-area: auto / span 2;
  64. }
  65. .col-1 {
  66. grid-area: auto / span 1;
  67. }

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>模拟bootstrap/layui的12列栅格布局组件</title>
  8. <link rel="stylesheet" href="style.css">
  9. </head>
  10. <body>
  11. <div class="container">
  12. <!-- 一等份 -->
  13. <!-- 栅格布局分为二步:
  14. 1.先创建一个行
  15. 2.在行中进行列的划分 -->
  16. <div class="row">
  17. <span class="item col-12">12列</span>
  18. </div>
  19. <!-- 二等分 -->
  20. <div class="row">
  21. <span class="item col-6">6列</span>
  22. <span class="item col-6">6列</span>
  23. </div>
  24. <!-- 三等分 -->
  25. <div class="row">
  26. <span class="item col-4">4列</span>
  27. <span class="item col-4">4列</span>
  28. <span class="item col-4">4列</span>
  29. </div>
  30. <!-- 四等分 -->
  31. <div class="row">
  32. <span class="item col-3">3列</span>
  33. <span class="item col-3">3列</span>
  34. <span class="item col-3">3列</span>
  35. <span class="item col-3">3列</span>
  36. </div>
  37. <!-- 十二等分 -->
  38. <div class="row">
  39. <span class="item col-1">1列</span>
  40. <span class="item col-1">1列</span>
  41. <span class="item col-1">1列</span>
  42. <span class="item col-1">1列</span>
  43. <span class="item col-1">1列</span>
  44. <span class="item col-1">1列</span>
  45. <span class="item col-1">1列</span>
  46. <span class="item col-1">1列</span>
  47. <span class="item col-1">1列</span>
  48. <span class="item col-1">1列</span>
  49. <span class="item col-1">1列</span>
  50. <span class="item col-1">1列</span>
  51. </div>
  52. <!-- 左中右三列,左右相同,中间不同 -->
  53. <div class="row">
  54. <span class="item col-3">3列</span>
  55. <span class="item col-6">6列</span>
  56. <span class="item col-3">3列</span>
  57. </div>
  58. </div>
  59. </body>
  60. </html>

使用封装好的grid布局组件来写一个圣杯布局 代码

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>使用封装好的grid布局组件来写一个圣杯布局</title>
  8. <link rel="stylesheet" href="grid.css">
  9. <style>
  10. .row:nth-of-type(2){
  11. height: 80vh;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <!-- 通用三列布局 -->
  17. <div class="container">
  18. <!-- 页眉 -->
  19. <div class="row">
  20. <div class="item col-12 header">header</div>
  21. </div>
  22. <!-- 主体 -->
  23. <div class="row">
  24. <div class="item col-2 header">left</div>
  25. <div class="item col-8 header">main</div>
  26. <div class="item col-2 header">right</div>
  27. </div>
  28. <!-- 页脚 -->
  29. <div class="row">
  30. <div class="item col-12 header">footer</div>
  31. </div>
  32. </div>
  33. </body>
  34. </html>

仿写php中文网首页

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>grid仿php.cn首页</title>
  8. <link rel="stylesheet" href="css/php.css">
  9. </head>
  10. <body>
  11. <!-- 页眉 -->
  12. <header>
  13. <div class="logo">
  14. <a href="http://" target="_blank" title="php中文网"></a>
  15. </div>
  16. <ul class="top-navs">
  17. <li>
  18. <a href="#" class="item">首页</a>
  19. </li>
  20. <li>
  21. <a href="#" class="item">视频教程</a>
  22. </li>
  23. <li>
  24. <a href="#" class="item">入门教程</a>
  25. </li>
  26. <li>
  27. <a href="#" class="item">社区问答</a>
  28. </li>
  29. <li>
  30. <a href="#" class="item">技术文章</a>
  31. <span></span>
  32. </li>
  33. <li>
  34. <a href="#" class="item">编程词典</a>
  35. <span></span>
  36. </li>
  37. <li>
  38. <a href="#" class="item">资源下载</a>
  39. <span></span>
  40. </li>
  41. <li>
  42. <a href="#" class="item">工具下载</a>
  43. <span></span>
  44. </li>
  45. <li>
  46. <a href="#" class="item">PHP培训</a>
  47. <span></span>
  48. </li>
  49. </ul>
  50. <div class="user-card-box">
  51. <img src="https://img.php.cn/upload/avatar/000/524/683/603603465c46e400.jpg" height="40" width="40">
  52. </div>
  53. </header>
  54. <!-- 主体顶部区 -->
  55. <div class="main-top">
  56. <!-- 侧边菜单 -->
  57. <ul class="menus">
  58. <li class="item">
  59. <h5>php开发</h5>
  60. <h5>></h5>
  61. </li>
  62. <li class="item">
  63. <h5>前端开发</h5>
  64. <h5>></h5>
  65. </li>
  66. <li class="item">
  67. <h5>服务端开发</h5>
  68. <h5>></h5>
  69. </li>
  70. <li class="item">
  71. <h5>移动开发</h5>
  72. <h5>></h5>
  73. </li>
  74. <li class="item">
  75. <h5>数据库</h5>
  76. <h5>></h5>
  77. </li>
  78. <li class="item">
  79. <h5>服务器运维&下载</h5>
  80. <h5>></h5>
  81. </li>
  82. <li class="item">
  83. <h5>在线工具箱</h5>
  84. <h5>></h5>
  85. </li>
  86. <li class="item">
  87. <h5>常用类库</h5>
  88. <h5>></h5>
  89. </li>
  90. </ul>
  91. <!-- 顶部菜单 -->
  92. <ul class="navs">
  93. <li>
  94. <div>
  95. <a href="">PHP头条</a>
  96. <h6></h6>
  97. </div>
  98. </li>
  99. <li>
  100. <div>
  101. <a href="">独孤九贱</a>
  102. <h6></h6>
  103. </div>
  104. </li>
  105. <li>
  106. <div>
  107. <a href="">学习路线</a>
  108. <h6></h6>
  109. </div>
  110. </li>
  111. <li>
  112. <div>
  113. <a href="">在线工具</a>
  114. <h6></h6>
  115. </div>
  116. </li>
  117. <li>
  118. <div>
  119. <a href="">趣味课堂</a>
  120. <h6></h6>
  121. </div>
  122. </li>
  123. <li>
  124. <div>
  125. <a href="">社区问答</a>
  126. <h6></h6>
  127. </div>
  128. </li>
  129. <li>
  130. <div>
  131. <a href="">课程直播</a>
  132. <h6></h6>
  133. </div>
  134. </li>
  135. <li>
  136. <input type="text" placeholder="输入关键字搜索">
  137. </li>
  138. </ul>
  139. <!-- 轮播图 -->
  140. <div class="slider">
  141. <img src="https://img.php.cn/upload/article/000/000/001/6034a327aef30703.png" alt="">
  142. </div>
  143. <!-- 底部的课程推荐 -->
  144. <ul class="course">
  145. <li>
  146. <a href=""><img src="https://www.php.cn/static/images/index_yunv.jpg" alt=""></a>
  147. </li>
  148. <li>
  149. <a href=""><img src="https://www.php.cn/static/images/index_php_item2_.png?1" alt=""></a>
  150. </li>
  151. <li>
  152. <a href=""><img src="https://www.php.cn/static/images/index_php_item3.jpg?1" alt=""></a>
  153. </li>
  154. <li>
  155. <a href=""><img src="https://www.php.cn/static/images/index_php_new4.jpg?1" alt=""></a>
  156. </li>
  157. </ul>
  158. </div>
  159. <!-- 广告区 -->
  160. <div class="index_ad_top">
  161. <a href="">
  162. <img src="https://img.php.cn/upload/article/000/000/001/6034a36c9c07c118.png" alt="">
  163. </a>
  164. </div>
  165. <!-- 头条 -->
  166. <div class="headline">
  167. <div class="article">
  168. <div class="panel-title">头条</div>
  169. <ul>
  170. <li>
  171. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  172. </li>
  173. <li>
  174. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  175. </li>
  176. <li>
  177. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  178. </li>
  179. <li>
  180. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  181. </li>
  182. <li>
  183. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  184. </li>
  185. <li>
  186. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  187. </li>
  188. <li>
  189. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  190. </li>
  191. <li>
  192. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  193. </li>
  194. <li>
  195. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  196. </li>
  197. <li>
  198. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  199. </li>
  200. <li>
  201. <a href="">php中文网原创视频:《天龙八部》公益php培训系列课程汇总!</a>
  202. </li>
  203. </ul>
  204. </div>
  205. <div class="course">
  206. <div class="panel-title">最新课程</div>
  207. <ul>
  208. <li>
  209. <a href="">
  210. <img src="https://img.php.cn/upload/course/000/000/013/6049da2b3898c385.jpg" alt="">
  211. <div class="php-course-intro">
  212. <h3><i>初级</i>php8,我来也</h3>
  213. </div>
  214. </a>
  215. </li>
  216. <li>
  217. <a href="">
  218. <img src="https://img.php.cn/upload/course/000/000/013/6049da2b3898c385.jpg" alt="">
  219. <div class="php-course-intro">
  220. <h3><i>初级</i>php8,我来也</h3>
  221. </div>
  222. </a>
  223. </li>
  224. <li>
  225. <a href="">
  226. <img src="https://img.php.cn/upload/course/000/000/013/6049da2b3898c385.jpg" alt="">
  227. <div class="php-course-intro">
  228. <h3><i>初级</i>php8,我来也</h3>
  229. </div>
  230. </a>
  231. </li>
  232. <li>
  233. <a href="">
  234. <img src="https://img.php.cn/upload/course/000/000/013/6049da2b3898c385.jpg" alt="">
  235. <div class="php-course-intro">
  236. <h3><i>初级</i>php8,我来也</h3>
  237. </div>
  238. </a>
  239. </li>
  240. <li>
  241. <a href="">
  242. <img src="https://img.php.cn/upload/course/000/000/013/6049da2b3898c385.jpg" alt="">
  243. <div class="php-course-intro">
  244. <h3><i>初级</i>php8,我来也</h3>
  245. </div>
  246. </a>
  247. </li>
  248. <li>
  249. <a href="">
  250. <img src="https://img.php.cn/upload/course/000/000/013/6049da2b3898c385.jpg" alt="">
  251. <div class="php-course-intro">
  252. <h3><i>初级</i>php8,我来也</h3>
  253. </div>
  254. </a>
  255. </li>
  256. </ul>
  257. </div>
  258. <div class="manual">
  259. <div class="panel-title">常用手册</div>
  260. <ul>
  261. <li>
  262. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg" alt="">
  263. <p>php手册Linux手册ThinkPHP6.0CI手册大全</p>
  264. </li>
  265. <li>
  266. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg" alt="">
  267. <p>php手册Linux手册ThinkPHP6.0CI手册大全</p>
  268. </li>
  269. <li>
  270. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg" alt="">
  271. <p>php手册Linux手册ThinkPHP6.0CI手册大全</p>
  272. </li>
  273. <li>
  274. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg" alt="">
  275. <p>php手册Linux手册ThinkPHP6.0CI手册大全</p>
  276. </li>
  277. <li>
  278. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg" alt="">
  279. <p>php手册Linux手册ThinkPHP6.0CI手册大全</p>
  280. </li>
  281. <li>
  282. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg" alt="">
  283. <p>php手册Linux手册ThinkPHP6.0CI手册大全</p>
  284. </li>
  285. </ul>
  286. </div>
  287. </div>
  288. <!-- 课程列表区 -->
  289. <div class="main-courses">
  290. <div class="title">
  291. <div>
  292. <\>
  293. </div>
  294. <h2>php入门精品课程</h2>
  295. <div>
  296. <\>
  297. </div>
  298. </div>
  299. <ul class="course-list">
  300. <li>
  301. <a href="">
  302. <img src="https://www.php.cn/static/images/index_learn_first.jpg" alt="">
  303. </a>
  304. </li>
  305. <li>
  306. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5b63c72c61569244.png" alt=""></a>
  307. <div class="php-course-intro">
  308. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  309. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  310. </div>
  311. <div class="php-course-bottom">
  312. <span>1W+次播放</span>
  313. </div>
  314. </li>
  315. <li>
  316. <a href=""><img src="https://img.php.cn/upload/course/000/126/153/5aa23f0ded921649.jpg" alt=""></a>
  317. <div class="php-course-intro">
  318. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  319. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  320. </div>
  321. <div class="php-course-bottom">
  322. <span>1W+次播放</span>
  323. </div>
  324. </li>
  325. <li>
  326. <a href=""><img src="https://img.php.cn/upload/course/000/126/153/5ab346fc62ce4221.jpg" alt=""></a>
  327. <div class="php-course-intro">
  328. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  329. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  330. </div>
  331. <div class="php-course-bottom">
  332. <span>1W+次播放</span>
  333. </div>
  334. </li>
  335. <li>
  336. <a href=""><img src="https://img.php.cn/upload/course/000/126/153/5acc118f11d6b969.jpg" alt=""></a>
  337. <div class="php-course-intro">
  338. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  339. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  340. </div>
  341. <div class="php-course-bottom">
  342. <span>1W+次播放</span>
  343. </div>
  344. </li>
  345. <li>
  346. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d1c6e0d2b744633.jpg" alt=""></a>
  347. <div class="php-course-intro">
  348. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  349. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  350. </div>
  351. <div class="php-course-bottom">
  352. <span>1W+次播放</span>
  353. </div>
  354. </li>
  355. <li>
  356. <a href=""><img src="https://img.php.cn/upload/course/000/001/120/5a9fb97057b15707.jpeg" alt=""></a>
  357. <div class="php-course-intro">
  358. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  359. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  360. </div>
  361. <div class="php-course-bottom">
  362. <span>1W+次播放</span>
  363. </div>
  364. </li>
  365. <li>
  366. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d24019911a24370.jpg" alt=""></a>
  367. <div class="php-course-intro">
  368. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  369. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  370. </div>
  371. <div class="php-course-bottom">
  372. <span>1W+次播放</span>
  373. </div>
  374. </li>
  375. <li>
  376. <a href=""><img src="https://img.php.cn/upload/course/000/000/003/5a699f1b2da2b398.jpg" alt=""></a>
  377. <div class="php-course-intro">
  378. <h3><i>高级</i>编程学习方法分享直播公益课</h3>
  379. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  380. </div>
  381. <div class="php-course-bottom">
  382. <span>1W+次播放</span>
  383. </div>
  384. </li>
  385. <li>
  386. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5cecd27a4348b582.jpg" alt=""></a>
  387. <div class="php-course-intro">
  388. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  389. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  390. </div>
  391. <div class="php-course-bottom">
  392. <span>1W+次播放</span>
  393. </div>
  394. </li>
  395. <li>
  396. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d1c6dfc9eb09885.jpg" alt=""></a>
  397. <div class="php-course-intro">
  398. <h3><i>中级</i>编程学习方法分享直播公益课</h3>
  399. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  400. </div>
  401. <div class="php-course-bottom">
  402. <span>1W+次播放</span>
  403. </div>
  404. </li>
  405. <li>
  406. <a href=""><img src="https://img.php.cn/upload/course/000/000/003/5a13c87351613730.jpg" alt=""></a>
  407. <div class="php-course-intro">
  408. <h3><i>中级</i>编程学习方法分享直播公益课</h3>
  409. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  410. </div>
  411. <div class="php-course-bottom">
  412. <span>1W+次播放</span>
  413. </div>
  414. </li>
  415. <li>
  416. <a href=""><img src="https://img.php.cn/upload/course/000/171/829/5b19ef2990649817.jpg" alt=""></a>
  417. <div class="php-course-intro">
  418. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  419. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  420. </div>
  421. <div class="php-course-bottom">
  422. <span>1W+次播放</span>
  423. </div>
  424. </li>
  425. <li>
  426. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d240300be85b731.jpg" alt=""></a>
  427. <div class="php-course-intro">
  428. <h3><i>高级</i>编程学习方法分享直播公益课</h3>
  429. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  430. </div>
  431. <div class="php-course-bottom">
  432. <span>1W+次播放</span>
  433. </div>
  434. </li>
  435. </ul>
  436. </div>
  437. <!-- 课程列表区 -->
  438. <div class="main-courses">
  439. <div class="title">
  440. <div>
  441. <\>
  442. </div>
  443. <h2>php入门精品课程</h2>
  444. <div>
  445. <\>
  446. </div>
  447. </div>
  448. <ul class="course-list">
  449. <li>
  450. <a href="">
  451. <img src="https://www.php.cn/static/images/index_learn_first.jpg" alt="">
  452. </a>
  453. </li>
  454. <li>
  455. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5b63c72c61569244.png" alt=""></a>
  456. <div class="php-course-intro">
  457. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  458. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  459. </div>
  460. <div class="php-course-bottom">
  461. <span>1W+次播放</span>
  462. </div>
  463. </li>
  464. <li>
  465. <a href=""><img src="https://img.php.cn/upload/course/000/126/153/5aa23f0ded921649.jpg" alt=""></a>
  466. <div class="php-course-intro">
  467. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  468. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  469. </div>
  470. <div class="php-course-bottom">
  471. <span>1W+次播放</span>
  472. </div>
  473. </li>
  474. <li>
  475. <a href=""><img src="https://img.php.cn/upload/course/000/126/153/5ab346fc62ce4221.jpg" alt=""></a>
  476. <div class="php-course-intro">
  477. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  478. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  479. </div>
  480. <div class="php-course-bottom">
  481. <span>1W+次播放</span>
  482. </div>
  483. </li>
  484. <li>
  485. <a href=""><img src="https://img.php.cn/upload/course/000/126/153/5acc118f11d6b969.jpg" alt=""></a>
  486. <div class="php-course-intro">
  487. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  488. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  489. </div>
  490. <div class="php-course-bottom">
  491. <span>1W+次播放</span>
  492. </div>
  493. </li>
  494. <li>
  495. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d1c6e0d2b744633.jpg" alt=""></a>
  496. <div class="php-course-intro">
  497. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  498. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  499. </div>
  500. <div class="php-course-bottom">
  501. <span>1W+次播放</span>
  502. </div>
  503. </li>
  504. <li>
  505. <a href=""><img src="https://img.php.cn/upload/course/000/001/120/5a9fb97057b15707.jpeg" alt=""></a>
  506. <div class="php-course-intro">
  507. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  508. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  509. </div>
  510. <div class="php-course-bottom">
  511. <span>1W+次播放</span>
  512. </div>
  513. </li>
  514. <li>
  515. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d24019911a24370.jpg" alt=""></a>
  516. <div class="php-course-intro">
  517. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  518. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  519. </div>
  520. <div class="php-course-bottom">
  521. <span>1W+次播放</span>
  522. </div>
  523. </li>
  524. <li>
  525. <a href=""><img src="https://img.php.cn/upload/course/000/000/003/5a699f1b2da2b398.jpg" alt=""></a>
  526. <div class="php-course-intro">
  527. <h3><i>高级</i>编程学习方法分享直播公益课</h3>
  528. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  529. </div>
  530. <div class="php-course-bottom">
  531. <span>1W+次播放</span>
  532. </div>
  533. </li>
  534. <li>
  535. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5cecd27a4348b582.jpg" alt=""></a>
  536. <div class="php-course-intro">
  537. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  538. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  539. </div>
  540. <div class="php-course-bottom">
  541. <span>1W+次播放</span>
  542. </div>
  543. </li>
  544. <li>
  545. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d1c6dfc9eb09885.jpg" alt=""></a>
  546. <div class="php-course-intro">
  547. <h3><i>中级</i>编程学习方法分享直播公益课</h3>
  548. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  549. </div>
  550. <div class="php-course-bottom">
  551. <span>1W+次播放</span>
  552. </div>
  553. </li>
  554. <li>
  555. <a href=""><img src="https://img.php.cn/upload/course/000/000/003/5a13c87351613730.jpg" alt=""></a>
  556. <div class="php-course-intro">
  557. <h3><i>中级</i>编程学习方法分享直播公益课</h3>
  558. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  559. </div>
  560. <div class="php-course-bottom">
  561. <span>1W+次播放</span>
  562. </div>
  563. </li>
  564. <li>
  565. <a href=""><img src="https://img.php.cn/upload/course/000/171/829/5b19ef2990649817.jpg" alt=""></a>
  566. <div class="php-course-intro">
  567. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  568. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  569. </div>
  570. <div class="php-course-bottom">
  571. <span>1W+次播放</span>
  572. </div>
  573. </li>
  574. <li>
  575. <a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d240300be85b731.jpg" alt=""></a>
  576. <div class="php-course-intro">
  577. <h3><i>高级</i>编程学习方法分享直播公益课</h3>
  578. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  579. </div>
  580. <div class="php-course-bottom">
  581. <span>1W+次播放</span>
  582. </div>
  583. </li>
  584. </ul>
  585. </div>
  586. <!-- 页脚 -->
  587. <footer>
  588. <div class="left">
  589. <ul class="bottom-navs">
  590. <li><a href="">网站首页</a></li>
  591. <li><a href="">PHP视频</a></li>
  592. <li><a href="">PHP代码</a></li>
  593. <li><a href="">PHP手册</a></li>
  594. <li><a href="">词条</a></li>
  595. <li><a href="">手记</a></li>
  596. <li><a href="">编程词典</a></li>
  597. <li><a href="">php培训</a></li>
  598. </ul>
  599. <div>
  600. php中文网:公益在线php培训,帮助PHP学习者快速成长!
  601. </div>
  602. <div>
  603. Copyright 2014-2021 https://www.php.cn/ All Rights Reserved | 苏州跃动光标网络科技有限公司 |
  604. </div>
  605. </div>
  606. <div class="right">
  607. <img src="" alt="">
  608. <img src="" alt="">
  609. </div>
  610. </footer>
  611. </body>
  612. </html>

  1. /* 初始化 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. li {
  8. list-style: none;
  9. }
  10. a {
  11. color: #444;
  12. text-decoration: none;
  13. }
  14. body {
  15. background-color: #f3f5f7;
  16. }
  17. /* -------------------- */
  18. /* 页眉 */
  19. header {
  20. min-width: 1200px;
  21. height: 60px;
  22. color: #999;
  23. background-color: black;
  24. margin-bottom: 30px;
  25. display: flex;
  26. align-items: center;
  27. }
  28. header .logo a {
  29. display: inline-block;
  30. height: 60px;
  31. width: 140px;
  32. background: url(https://www.php.cn/static/images/logo.png) no-repeat center center;
  33. background-size: 100%;
  34. }
  35. header .top-navs {
  36. margin-left: 30px;
  37. text-align: center;
  38. line-height: 60px;
  39. height: 60px;
  40. display: flex;
  41. }
  42. header .top-navs li {
  43. margin-right: 10px;
  44. height: 60px;
  45. cursor: pointer;
  46. }
  47. header .top-navs li a {
  48. display: inline-block;
  49. padding: 0 20px;
  50. width: 100%;
  51. height: 100%;
  52. font-size: 14px;
  53. color: rgba(255, 255, 255, .7);
  54. }
  55. header>ul.top-navs>li a:hover {
  56. color: rgb(255, 255, 255);
  57. border-bottom: 5px solid lightgreen;
  58. }
  59. header>ul.top-navs>li a:hover+span {}
  60. header>ul.top-navs>li:first-of-type {
  61. background-color: #444;
  62. }
  63. header>ul.top-navs>li {
  64. position: relative;
  65. }
  66. header>ul.top-navs>li:nth-last-of-type(3) span,
  67. header>ul.top-navs>li:nth-last-of-type(4) span,
  68. header>ul.top-navs>li:nth-last-of-type(5) span {
  69. width: 0;
  70. height: 0;
  71. border-style: solid dashed dashed;
  72. border-color: #fff transparent transparent;
  73. border-top-color: rgb(255, 255, 255);
  74. overflow: hidden;
  75. cursor: pointer;
  76. transition: all .2s;
  77. -webkit-transition: all .2s;
  78. position: absolute;
  79. top: 50%;
  80. right: 3px;
  81. margin-top: -3px;
  82. border-width: 6px;
  83. border-top-color: rgba(255, 255, 255, .7);
  84. }
  85. header>ul.top-navs>li:nth-last-of-type(2) span {
  86. position: absolute;
  87. background-color: red;
  88. width: 8px;
  89. height: 8px;
  90. border-radius: 50%;
  91. top: 24px;
  92. right: 6px;
  93. }
  94. header>ul.top-navs>li:last-of-type span {
  95. position: absolute;
  96. background-color: red;
  97. width: 20px;
  98. height: 20px;
  99. top: 3px;
  100. left: 70px;
  101. line-height: 20px;
  102. font-size: 12px;
  103. color: #fff;
  104. border-radius: 4px;
  105. }
  106. header .user-card-box {
  107. margin-right: 20px;
  108. margin-left: auto;
  109. }
  110. header .user-card-box img {
  111. border-radius: 50%;
  112. vertical-align: middle;
  113. }
  114. /* 页脚 */
  115. footer {
  116. display: grid;
  117. grid-auto-flow: column;
  118. grid-template-columns: 1000px 200px;
  119. height: 160px;
  120. color: #666;
  121. background-color: #444;
  122. place-items: center start;
  123. place-content: center;
  124. }
  125. footer>div.left {
  126. min-width: 1200px;
  127. height: 160px;
  128. display: grid;
  129. place-items: center start;
  130. margin: 0 auto;
  131. }
  132. footer .left>ul.bottom-navs {
  133. display: grid;
  134. grid-auto-flow: column;
  135. gap: 10px;
  136. margin-left: 10px;
  137. }
  138. footer .left>ul.bottom-navs>li>a {
  139. color: white;
  140. }
  141. /* 主体顶部区 */
  142. .main-top {
  143. height: 540px;
  144. width: 1200px;
  145. margin-bottom: 30px;
  146. display: grid;
  147. grid-template-columns: 200px 1fr;
  148. grid-template-rows: 60px 1fr 120px;
  149. margin: auto;
  150. background: #fff;
  151. box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
  152. }
  153. /* 左侧导航区 */
  154. .main-top>.menus {
  155. grid-area: span 3;
  156. background-color: #444;
  157. color: #ccc;
  158. border-radius: 10px 0 0 10px;
  159. padding: 10px 0 10px 0;
  160. display: grid;
  161. grid-template-columns: 1fr;
  162. place-items: center space-between;
  163. }
  164. .main-top>.menus>li.item {
  165. display: grid;
  166. grid-auto-flow: column;
  167. grid-template-columns: 1fr 20px;
  168. padding: 0 0px 0 20px;
  169. place-items: center start;
  170. }
  171. .main-top>.menus>li.item:hover {
  172. background-color: #666;
  173. cursor: pointer;
  174. }
  175. /* 顶部的导航区 */
  176. .main-top>ul.navs {
  177. display: grid;
  178. grid-template-columns: repeat(8, 103px) 1fr;
  179. place-items: center;
  180. border-radius: 0 10px 0 0;
  181. }
  182. .main-top>ul.navs>li>div {
  183. font-size: 14px;
  184. display: grid;
  185. grid-auto-flow: column;
  186. place-items: center center;
  187. }
  188. .main-top>ul.navs>li>div>h6 {
  189. width: 20px;
  190. color: white;
  191. text-align: center;
  192. margin-left: 2px;
  193. border-radius: 3px;
  194. padding: 3px;
  195. }
  196. .main-top>ul.navs>li:nth-of-type(1)>div>h6 {
  197. background-color: orangered;
  198. }
  199. .main-top>ul.navs>li:nth-of-type(3)>div>h6 {
  200. background-color: #444;
  201. }
  202. .main-top>ul.navs>li:nth-of-type(5)>div>h6 {
  203. background-color: orange;
  204. }
  205. .main-top>ul.navs>li:last-of-type {
  206. background-color: #eee;
  207. height: 36px;
  208. width: 250px;
  209. /* 搜索 */
  210. place-self: center start;
  211. padding: 0px 10px 0 10px;
  212. }
  213. .main-top>ul.navs>li:last-of-type>input {
  214. height: 36px;
  215. border: none;
  216. outline: none;
  217. background-color: #eee;
  218. }
  219. /* 轮播图 */
  220. .main-top .slider {
  221. background-color: #ccc;
  222. }
  223. /* 底部的课程推荐 */
  224. .main-top>ul.course>li>a>img {
  225. background-color: violet;
  226. cursor: pointer;
  227. border-radius: 10px;
  228. }
  229. .main-top>ul.course {
  230. grid-template-columns: repeat(4, 1fr);
  231. gap: 10px;
  232. padding: 10px;
  233. display: grid;
  234. border-radius: 0 0 10px 0;
  235. }
  236. /* -------------------- */
  237. /* 广告 */
  238. .index_ad_top {
  239. width: 1200px;
  240. margin: 20px auto;
  241. text-align: center;
  242. }
  243. /* 头条 */
  244. .headline {
  245. margin: 0 auto;
  246. width: 1200px;
  247. height: 416px;
  248. /* border: 1px solid red; */
  249. display: grid;
  250. grid-template-columns: 300px 620px 260px;
  251. gap: 10px;
  252. }
  253. .headline>div {
  254. background-color: #fff;
  255. border-radius: 10px;
  256. }
  257. .headline .panel-title {
  258. height: 35px;
  259. line-height: 35px;
  260. font-weight: 550;
  261. margin: 0 15px 10px;
  262. border-bottom: 1px dotted #e9e9e9;
  263. color: #343535;
  264. font-size: 14px;
  265. }
  266. .headline .article ul {
  267. padding: 0 10px;
  268. }
  269. .headline .article ul li {
  270. white-space: nowrap;
  271. overflow: hidden;
  272. text-overflow: ellipsis;
  273. margin-bottom: 10px;
  274. font-size: 14px;
  275. }
  276. .headline .course ul {
  277. padding: 20px;
  278. display: grid;
  279. grid-template-columns: repeat(3, 170px);
  280. grid-template-rows: repeat(2, 140px);
  281. place-items: center;
  282. place-content: center;
  283. gap: 20px;
  284. }
  285. .headline .course ul li {
  286. width: 172px;
  287. height: 140px;
  288. float: left;
  289. margin: 10px 10px 20px 10px;
  290. box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
  291. position: relative;
  292. border-radius: 8px;
  293. box-sizing: border-box;
  294. overflow: hidden;
  295. position: relative;
  296. }
  297. .headline .course ul .php-course-intro {
  298. padding: 5px;
  299. border-radius: 8px;
  300. box-sizing: border-box;
  301. position: absolute;
  302. transition: top .5s;
  303. top: 70px;
  304. height: 144px;
  305. width: 100%;
  306. background: #fff;
  307. }
  308. .headline .course ul .php-course-intro h3 {
  309. padding-left: 10px;
  310. font-size: 14px;
  311. max-height: 40px;
  312. overflow: hidden;
  313. line-height: 21px;
  314. }
  315. .headline .course img {
  316. width: 170px;
  317. height: 90px;
  318. margin-bottom: 10px;
  319. border-radius: 8px;
  320. }
  321. .headline .course ul li:hover .php-course-intro {
  322. top: 45px;
  323. }
  324. .headline .manual ul {
  325. padding: 20px;
  326. }
  327. .headline .manual ul li {
  328. display: grid;
  329. grid-template-columns: 30% 70%;
  330. margin-bottom: 10px;
  331. }
  332. .headline .manual ul li p {
  333. font-size: 14px;
  334. }
  335. .headline .manual ul img {
  336. width: 40px;
  337. margin-right: 10px;
  338. }
  339. /* -------------------- */
  340. /* 主体课程 */
  341. .main-courses {
  342. width: 1200px;
  343. height: 646px;
  344. padding: 15px;
  345. background-color: #fff;
  346. margin: 30px auto;
  347. display: grid;
  348. grid-template-rows: 50px 1fr;
  349. gap: 20px;
  350. border-radius: 10px;
  351. box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
  352. }
  353. /* 标题 */
  354. .main-courses .title {
  355. color: #444;
  356. display: grid;
  357. grid-auto-flow: column;
  358. grid-template-columns: 1fr 200px 1fr;
  359. place-items: center center;
  360. margin-bottom: 30px;
  361. font-weight: bolder;
  362. }
  363. .main-courses .title>div:first-of-type {
  364. color: blue;
  365. place-self: center end;
  366. }
  367. .main-courses .title>div:last-of-type {
  368. color: blue;
  369. place-self: center start;
  370. }
  371. .main-courses .course-list {
  372. display: grid;
  373. grid-template-columns: repeat(5, 217px);
  374. grid-template-rows: repeat(3, 172px);
  375. gap: 20px;
  376. }
  377. .main-courses .course-list>li>a>img {
  378. width: 100%;
  379. border-radius: 10px;
  380. }
  381. .main-courses .course-list>li:first-of-type {
  382. grid-area: span 2;
  383. }
  384. .main-courses .course-list>li {
  385. overflow: hidden;
  386. position: relative;
  387. border-radius: 8px;
  388. box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
  389. }
  390. .main-courses .course-list>li .php-course-intro {
  391. border-radius: 8px;
  392. box-sizing: border-box;
  393. position: absolute;
  394. padding: 0 20px;
  395. transition: top .5s;
  396. top: 90px;
  397. height: 144px;
  398. width: 100%;
  399. background: #fff;
  400. }
  401. .main-courses .course-list>li:hover .php-course-intro {
  402. top: 10px;
  403. cursor: pointer;
  404. }
  405. .php-course-intro h3 {
  406. margin: 0;
  407. padding: 16px 0 6px;
  408. font-size: 14px;
  409. max-height: 40px;
  410. overflow: hidden;
  411. color: #07111b;
  412. line-height: 21px;
  413. }
  414. .php-course-intro h3 i {
  415. margin-top: 2px;
  416. margin-right: 4px;
  417. padding: 2px;
  418. font-style: normal;
  419. font-size: 12px;
  420. color: #fff;
  421. line-height: 12px;
  422. border-radius: 1px;
  423. background-color: #93999f;
  424. }
  425. .php-course-intro p {
  426. color: #93999f;
  427. font-size: 12px;
  428. height: 40px;
  429. overflow: hidden;
  430. line-height: 20px;
  431. }
  432. .php-course-bottom {
  433. position: absolute;
  434. padding: 0 20px;
  435. bottom: 0;
  436. box-sizing: border-box;
  437. width: 100%;
  438. height: 42px;
  439. background-color: #fff;
  440. color: #93999f;
  441. font-size: 12px;
  442. line-height: 36px;
  443. }

效果图:



预览地址:http://easys.ltd/php/

总结

轨道排列方式:”行优先” 和 “列优先”
grid-auto-flow: row;
grid-auto-flow: column;

隐式轨道: 新项目显示的轨道
隐式轨道的行高:grid-auto-rows
隐式轨道的列宽:grid-auto-columns

grid-area: 设置任何一个项目所在的网格单元的区域
格式” grid-area:行起始编号 / 列起始编号 / 行结束编号 / 列结束编;”

place-items: 所有项目在网格单元中的对齐方式
格式”place-items: center center; “

place-self: 某一个项目在网格单元中的对齐方式
格式”place-self: center center; “

place-content: 项目在网格容器中的对齐方式(垂直方向 水平方向)
格式”place-content: 垂直方向 水平方向”
将所有项目做为一个整体在容器中对齐:place-content: center center;
将所有项目打散成独立个体在容器中设置对齐方式:place-content: space-around space-evenly;

命名式的网格区域:
使用grid-area关联(header { grid-area: header; }) 再使用grid-template-areas来分配( grid-template-areas: ‘header header header’ ‘. main .’ ‘footer footer footer’;)

批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学