前端小白的学习之路(CSS3 二)

提示:网格布局,背景与阴影

目录

一、网格布局

二、背景

1.图片背景

2.边框背景图

[三 、阴影](#三 、阴影)

1.盒子阴影

2.字体阴影

拓展:自定义字体


一、网格布局

开启网格布局

css 复制代码
display: grid;

设置多少行,每行的高度是多少

css 复制代码
/*写法一*/
rid-template-rows: 100px; 
/*写法二*/
grid-template-rows: repeat(1, 100px);

设置多少列,每列的宽度是多少

css 复制代码
/*写法一*/
grid-template-columns: 100px;

/*写法二*/
grid-template-columns: repeat(1, 100px);

设置li标签的位置居中

css 复制代码
justify-content: center;

align-content: center;

网格标记

html 复制代码
<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>基本模板</title>

</head>
    <style>
        .wrap {
            width: 320px;
            height: 320px;
            background-color: pink;
            /* 设置网格盒子 */
            display: grid;
            /* 设置三行三列标签 */
            grid-template-rows: repeat(3, 100px);
            grid-template-columns: repeat(3, 100px);
            /* 1 : 1 : 1 */
            /* grid-template-columns: repeat(3,1fr);  */
            /* 1 : 2 : 1 */
            /* grid-template-columns: 1fr  2fr 1fr; */
            /* grid-template-columns: 100px  100px 100px; */

            /* 设置行间距 */
            row-gap: 10px;
            /* 设置列间距 */
            column-gap: 10px;

            /* 设置网格标记 (划分网格容器的区域)*/
            grid-template-areas: 'a b c'
                'e f g'
                'h i j';

        }


        .bg-red {
            background-color: red;
            /* 设置标签到f的位置 */
            grid-area: j;
        }

        .bg-green {
            background-color: green;
            /* 设置标签到g的位置 */
            grid-area: g;
        }

        .bg-blue {
            background-color: blue;
            grid-area: f;
        }

        .bg-yellow {
            background-color: yellow;
            grid-area: c;
        }

        .bg-orange {
            background-color: orange;
            grid-area: h;
        }

        .bg-deepskyblue {
            background-color: deepskyblue;
            grid-area: i;
        }
    </style>

<body>

    <div class="wrap">
        <div class="item bg-red"></div>
        <div class="item bg-green"></div>
        <div class="item bg-blue"></div>
        <div class="item bg-yellow"></div>
        <div class="item bg-orange"></div>
        <div class="item bg-deepskyblue"></div>
    </div>


</body>

</html>

二、背景

1.图片背景

设置背景图片

css 复制代码
background-image: url(./images/one1.jpg);

设置背景不重复

css 复制代码
 background-repeat: no-repeat;

设置图片从边框开始渲染 (内边距、内容), 背景图的起点

css 复制代码
/*从边框开始渲染*/
background-origin: border-box;
/*从内边距开始渲染*/
background-origin: padding-box; 
/*默认属性,从内容区开始渲染*/
background-origin: content-box;

把边框部分的背景图裁剪掉 (内边距、内容)

css 复制代码
background-clip: content-box;

**2.**边框背景图

设置标签边框图片

css 复制代码
border-image-source: url(./images/border-image2.png);

裁剪边框背景图

css 复制代码
border-image-slice: 60 60 60 60;

设置边框背景图平铺repeat,round(推荐) repeat

css 复制代码
border-image-repeat: round;

设置边框背景图的尺寸

css 复制代码
border-image-width: 20px;

设置边框背景图的位置(不能为负值)

css 复制代码
border-image-outset: 10px;

三 、阴影

1.盒子阴影

box-shadow:水平位置 垂直位置 [模糊程度 外延程度 阴影颜色 内阴影]

css 复制代码
box-shadow: 10px 10px 10px 5px gray inset;

2.字体阴影

text-shadow:offsetX,offsetY, 模糊度, 阴影颜色

css 复制代码
 text-shadow: 1px 1px 1px  white , -1px -1px 1px green;

拓展:自定义字体

css 复制代码
/*设置font-face可以通过font-family来设置自定义字体*/
@font-face {
   font-family: abc;
   src: url(./fonts/abc.ttf);/*网上找到字体资源*/
}
相关推荐
2303_Alpha3 天前
SpringBoot
笔记·学习
萘柰奈3 天前
Unity学习----【进阶】TextMeshPro学习(三)--进阶知识点(TMP基础设置,材质球相关,两个辅助工具类)
学习·unity
沐矢羽3 天前
Tomcat PUT方法任意写文件漏洞学习
学习·tomcat
好奇龙猫3 天前
日语学习-日语知识点小记-进阶-JLPT-N1阶段蓝宝书,共120语法(10):91-100语法+考え方13
学习
向阳花开_miemie3 天前
Android音频学习(十八)——混音流程
学习·音视频
工大一只猿3 天前
51单片机学习
嵌入式硬件·学习·51单片机
少年阿闯~~3 天前
CSS3的新特性
前端·javascript·css3
c0d1ng3 天前
量子计算学习(第十四周周报)
学习·量子计算
Hello_Embed3 天前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件
咸甜适中3 天前
rust语言 (1.88) 学习笔记:客户端和服务器端同在一个项目中
笔记·学习·rust