首页 > 其他分享 >CSS学习笔记

CSS学习笔记

时间:2024-06-18 17:56:48浏览次数:11  
标签:color 笔记 height 学习 width background border CSS 150px

一、盒子模型
1.简介
盒子模型是网页布局的基础,将页面中所有元素都看作是一个盒子,盒子都包含以下几个属性:width 宽度
height 高度
border 边框
padding 内边距
margin 外边距
2.盒子模型
2.1 border
表示盒子的边框

分为四个方向:

上top、右right、下bottom、左left
border-top、border-right、border-bottom、border-left

2.2 padding
表示盒子的内边距,即内容与边框之间的距离

2.3 margin
表示盒子的外边距,即盒子与盒子之间的距离

二、外边距的合并

也称为外边距的折叠,指的是两个块级元素垂直外边距相遇时,它们将合并为一个外边距,合并后的外边距值为其中较大的那个外边距值

两种情况:1.当一个元素出现在另一个元素上面时,第一个元素的下边距与第二元素的上边距会发生合并2.当一个元素包含在另一个元素中时,并且没有内边距或边框把外边距分隔开时,两个元素的上外边距会发生合并
外边距的合并的好处,让排版在视觉上显得更美观

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* .box1 {
            width: 200px;
            height: 200px;
            background-color: purple;
            margin-bottom: 20px;
        }
        
        .box2 {
            width: 200px;
            height: 200px;
            background-color: skyblue;
            margin-top: 10px;
        } */
        
        .bigbox {
            width: 500px;
            height: 500px;
            background-color: rgb(255, 94, 150);
            border: 1px solid rgba(89, 255, 0, 0);
        }
        
        .smallbox {
            width: 100px;
            height: 100px;
            background-color: #fff568;
            margin-top: 150px;
        }
    </style>
</head>

<body>
    <!-- <div class="box1"></div>
    <div class="box2"></div> -->
    <div class="bigbox">
        <div class="smallbox"></div>
    </div>
</body>

</html>

三、盒子阴影

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 150px;
            height: 150px;
            border: 1px solid red;
            margin: 150px auto;
            box-shadow: 5px 5px 1px 5px blue inset;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>

</html>

四、浮动属性
通过float属性来实现元素的浮动,可以让块级元素脱离常规的文档流,向左或向右移动,在同一行显示,如果一行显示不下,则会换行显示

常用取值:

left左浮动
right右浮动
none不浮动,默认值
设置float属性后,元素会浮在页面上层,此时父容器无法计算自己尺寸,如果我们还想显示父容器通常会在末尾添加一个清除了float属性的空的div来解决。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 800px;
            margin: 0 auto;
        }
        
        .obox {
            width: 190px;
            height: 400px;
            border: 1px solid red;
            text-align: center;
            line-height: 100px;
            float: right;
            /* 浮动   元素的对齐方式  左 右 */
            /* display: inline-block;
            margin-left: -2px; */
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="obox">1</div>
        <div class="obox">2</div>
        <div class="obox">3</div>
        <div class="obox">4</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>
        <div class="obox">5</div>


    </div>
</body>

</html>

浮动的影响

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bigbox {
            width: 800px;
            height: 150px;
            background-color: hsl(0, 100%, 62%);
            /* overflow: hidden; */
        }
        
        .smallbox1 {
            width: 150px;
            height: 150px;
            background-color: #fafa17;
            float: left;
        }
        
        .smallbox2 {
            width: 150px;
            height: 150px;
            background-color: #17fa22;
            float: right;
        }
        
        .bigbox2 {
            width: 800px;
            height: 800px;
            background-color: #0f33ff;
        }
    </style>
</head>

<body>
    <div class="bigbox">
        <div class="smallbox1"></div>
        <div class="smallbox2"></div>
    </div>
    <div class="bigbox2"></div>
</body>

</html>

标签:color,笔记,height,学习,width,background,border,CSS,150px
From: https://blog.csdn.net/m0_69397301/article/details/139778719

相关文章

  • 学习docker过程中,经常使用的命令
    常用命令:dockerps-a//查看正在运行的容器dockerps-all//查看所有的容器(包括正在运行的和已经停止的)dockerimages//列出所有镜像dockerexec-itmsb-mysql/bin/bash进入到容器中dockerrmcontainer_name_or_id//删除容器dockerrestartmsb-mysql-master//重启......
  • 【暑假Python上岸计划】最新20+Python实战案例,全程干货,30天看完即可接单就业!(基础+进阶
    前言今天给大家分享20+个基于python的实战案例,主要包含:数据分析、可视化、机器学习/深度学习、时序预测等,案例的主要特点:*提供源码:代码都是基于jupyternotebook,附带一定的注释,运行即可*数据齐全:大部分案例都有提供数据,部分案例使用内置数据集学习资料已打包,需要......
  • Linux系统概念及命令学习
    1.Linux系统基本概念多用户的系统:允许同时有很多个用户登录系统,使用系统里的资源多任务的系统:允许同时执行多个任务严格区分大小写:命令,选项,参数,文件名,目录名都严格区分大小写一切皆文件:硬件设备(内存、CPU、网卡、显示器、硬盘等等)都是以文件的形式存在的不管是文件还是目录......
  • js+css元素动态出现,前端让元素从底部动态显现,前端让元素从底部跳跃显示
    实现效果实现原理一点也不复杂,耐心看完,思路理解后直接复制粘贴即可使用1.为想要动态出现的元素添加指定class类名,我这里用(animate-element)2.监听屏幕滚动,屏幕滚动时,如果屏幕高度减去元素顶部相对于屏幕的位置大于0的话,说明已经滚动到当前元素,然后给这个元素添加c......
  • 揭秘In-Context Learning(ICL):大型语言模型如何通过上下文学习实现少样本高效推理[示
    揭秘In-ContextLearning(ICL):大型语言模型如何通过上下文学习实现少样本高效推理[示例设计、ICL机制详解]自GPT-3首次提出了In-ContextLearning(ICL)的概念而来,ICL目前已经变成了一种经典的LLMs使用方法。ICL,即In-ContextLearning,是一种让大型语言模型(LLMs)通过少量标注样本在......
  • 3、17算法学习(1)存在的问题(c中如何表示大、小顶堆)
    二路归并、逆序对多路归并,堆栈1、多路归并模板先将数据读入堆栈,然后取栈顶的最大值或最小值,最后再根据公式进行递推求出需要添加的元素。题目:https://www.acwing.com/problem/content/description/1264/https://www.acwing.com/problem/content/148/模板:intwork(intn......
  • Linux学习DAY5-vim程序编辑器
    一、vi与vim注:在Linux的系统中使用文本编辑器来编辑Linux参数配置文件在Linux中,绝大多数的配置文件都是以ASCII的纯文本形态存在。因此,可以利用简单的文本编辑软件修改设定。注:什么是纯文本文档?档案记录的是0与1,通过编码系统来将这些0与1转化为文字。学习vim的原因:  ......
  • LLM学习笔记
    1.评估榜单1.1.C-EvalC-Eval是一个全面的中文基础模型评估套件。它包含了13948个多项选择题,涵盖了52个不同的学科和四个难度级别。https://cevalbenchmark.com/static/leaderboard_zh.html?ref=nav.6aiq.com全部都是各个学科的选择题,例如:企业联合是指企业之间为增强市......
  • 算法课程笔记——普通莫队
    算法课程笔记——普通莫队......
  • 算法课程笔记——单调栈&单调队列
    算法课程笔记——单调栈&单调队列......