系统学习前端之CSS---day03

一、CSS引入的几种方式

行内式

  • 冗余代码多,代码量大
  • 不利于维护和修改
  • 优先级相对来说较高,个别特殊的效果可以使用,但是不要滥用
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>行内式引入css</title>
  </head>
  <body>
    <ul>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
      <li style="background-color: green;width: 100px;height: 100px;"></li>
    </ul>
  </body>
</html>

内嵌式

        在<head>标签里面通过<style>标签来写

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>内嵌式引入css</title>
    <style>
        div,p{
            width:500px;
            height:200px;
            background:greenyellow;
            color:hotpink;
        }
    </style>

  </head>
  <body>
    <div>
      <p></p>
    </div>
  </body>
</html>

外链式

        在<head>标签里面通过<link>标签把样式表给链接过来

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>外链式引入css</title>
    <link rel="stylesheet" href="index.css">
  </head>
  <body>
    <div>
      <p></p>
    </div>
  </body>
</html>

导入式

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>导入式引入css</title>
    <style>
      @import "index.css";
    </style>

  </head>
  <body>
    <div>
      <p></p>
    </div>
  </body>
</html>

二、清除默认样式

1、清除页面中元素默认自带的margin值和padding值

` * `是通配符选择器,代表选中页面中所有的元素,下面代码的意思就是,

把页面中所有元素默认自带的margin值和padding值都归为0.

*{
  margin:0;
  padding:0;
}

2、清除列表前面默认的样式

ul,ol{
  list-style: none;
}

3、清除a标签下划线

a{
  text-decoration: none;
}

三、基础样式的设置:

1、文本颜色的设置(color)

color属性: 设置文字颜色(可以继承的)

① 可以直接设置颜色的名字(开发中很少使用,因为不精确)

  • red
  • green
  • yellow
  • pink
  • blue
  • grey
  • purple
  • orange
  • lightblue
  • lightgreen
  • greenyellow
  • yellowgreen
  • .........

② 设置为三原色 红r 绿g 蓝b

    • 所有颜色都是由这三种颜色调制出来的
    • 每一个颜色的值都是 0-255之间
    • rgb(30,120,200)
    • 颜色还可以设置不透明度 ,可以使用 rgba(20,111,111,.7)

③ 颜色还可以设置为十六进制(不能设置透明度)

    • #加上16进制的颜色值 6位
    • #112233--> 11代表red的十六进制值 22代表green颜色的十六进制值 33代表blue颜色十六进制值
    • 十六进制颜色提供简写:当1,2位一样并且3,4位一样并且5,6一样的时候 可以每一位简写一个#112233-->#123 #aabb11-->#ab1 #000000-->#000 #111222-->#111222

2、关于a标签颜色的继承

  • a标签比较特殊,如果a标签没有href属性,a标签没有默认样式,那么继承颜色生效
  • 但是如果a标签拥有href属性,a标签链接的自带样色会盖过继承
  • 所以在开发中给a标签设置颜色,需要直接对a标签进行设置

3、font-family:设置字体(可以继承)

  • 常见中文字体:"Microsoft YaHei"、"SimHei"、"SimSun"
  • 但是我们设置的字体用户可能没有,我们需要设置备用字体在font-famliy后书写多个字体,使用逗号隔开,浏览器会依次检测支持为止,否则将执行默认字体
  • 如果是中文字体,或者是英文字体由多个单词组成需要加单引号或者双引号
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>font-famliy</title>
    <style>
      .box{
        font-family: "Microsoft YaHei";
        font-family: "SimSun";
        font-family: "SimHei";
        font-family: "SimHei","SimSun","Microsoft YaHei";
      }
    </style>
  </head>
  <body>
    <div class="box">
      哈哈哈哈
      <span>笑个鬼</span>
    </div>
  </body>
</html>

4、font-size:设置字体大小

  1. 常用的单位是px、em、rem
  2. 可以设置小数(低版本ie不支持)
  3. 字号最好不要设置为奇数
  4. 浏览器都有自己的默认字号大小和最小字号,谷歌浏览器默认字号大小是16px,谷歌浏览器支持的最小字号多数是12px如果设置12以下,字体不支持,但是如果设置字号为0 那么文字高度为0,消失!

5、字体风格:font-style(可以继承)

  • normal:正常多数元素的默认值对于默认倾斜或斜体的元素 i em 可以调整成正常非倾斜样式
  • italic 让元素呈现斜体 一般指的是一个字体在字体设计的过程中,会对一个文字设计 正常体 斜体 粗体 等状态而italic只是选择让使用斜体显示
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>字体风格</title>
    <style>
      em,i{
        font-style: normal;
      }
      .outer{
        font-style: italic;
      }
    </style>
  </head>
  <body>
    <div>
      <em>em</em>
      <i>i</i>
    </div>
    <div class="outer">
      outer中
      <!-- 继承斜体的样式 -->
      <span>span里</span>
    </div>
  </body>
</html>

6、font-weight:(继承)

用来定义字体的粗细 其实目前浏览器只支持3个级别 细 正常 粗

  1. normal:正常粗细 可以将默认加粗的字体进行改变为正常 比如 b strong
  2. bold:加粗
  3. 100-900 整除100的整数:因为浏览器只支持 细 粗 正常3个 所以100-300 是细,400-500 正常,600-900 加粗
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>font-weight 字体粗细</title>
    <style>
      .outer b,.outer strong{
        font-weight: normal;
      }
      .box{
        font-weight: bold;
      }
      .box span{
        font-weight: lighter;
      }
      .box span em{
        /*font-weight: lighter;*/
        font-weight: bolder;
      }
      
      .con{
        font-weight: 100;
      }
      
    </style>
  </head>
  <body>
    <div class="outer">
      <b>小b</b>
      <strong>小s</strong>
    </div>
    <div class="box">
      我是一个box
      <span>我是一个span <em>我是em</em></span>
    </div>
    <div class="con">
      我是con
    </div>
  </body>
</html>

7、text-indent首行文本缩进

  1. 单位是px 缩进的像素
  2. em单位 em是一个相对单位,1em=当前文字的字号大小 如果缩进两个文字 那么2em
  3. 只针对块级元素生效
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>10.text-indent首行文本缩进</title>
    <style>
      p{
        width: 200px;
        background-color: yellow;
        font-size:16px;
        /*text-indent: 32px;*/
        text-indent: 2em;
      }
      span{
        text-indent: 2em;
      }
    </style>
  </head>
  <body>
    <p>
      今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好今天天气真好
      <br>
      <span>
        真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊真的好呀啊
      </span>
    </p>
  </body>
</html>

8、text-align:(继承)

  1. 规定行内的内容如何相对于它的块级父元素水平方向对齐
  2. 并不是控制元素自己的对齐,只是控制它里边的行内容水平方向对齐
  • left:默认 左对齐
  • center:居中
  • right:右对齐
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>文本对齐</title>
    <style>
      .outer{
        width: 600px;
        height: 200px;
        background-color: red;
        text-align: center;
      }
      .con{
        width: 300px;
        height: 100px;
        background-color: yellow;
        
        text-align: center;
        text-align: right;
        line-height: 100px;
      }
    </style>
  </head>
  <body>
    <div class="outer">
      <div class="con">
        hello world <span>span</span>
      </div>
    </div>
  </body>
</html>

9、表示背景颜色:background-color

  • 背景颜色设置:background-color:颜色值(和color的颜色一致 十六进制 rgba 颜色单词)

10、text-decoration:文本修饰(不继承)

虽然不继承,但是延伸到后代元素,因为后代元素属于这个元素的下划线范围

  • none:取消下划线
  • underline:下划线
  • overline:上划线
  • line-through:删除线

11、一个元素的宽度(width) 表示高度(height)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>宽高</title>
    <style>
      div {
        width: 600px;
        height: 200px;
        background-color: red;
      }
  
    </style>
  </head>
  <body>
    <div>
      
    </div>
  </body>
</html>

12、让块级元素水平居中:margin:0 auto;

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>margin</title>
    <style>
      div{
      width:100px;
      height:100px;
      background:green;
      margin:0 auto;
    }
  
    </style>
  </head>
  <body>
    <div>
      
    </div>
  </body>
</html>

13、边框:border

<style>
div{
  width:200px;
  height:200px;
  /* border:2px solid darkturquoise; */
  border:2px dashed darkturquoise; 
}
</style>

14、border 是简写属性,设置所有的边框属性。

可以按顺序设置如下属性:

  • border-width
  • border-style
  • border-color

border-style可能的值:

15、想让两个块级元素在一行显示,转换为行内块产生的问题

两个块级元素之间会有缝隙(原因回车造成的)

不仅仅两个块元素在一行,两张图片在一行都会存在这个问题

解决的办法:

  • 在结构中消除换行符
  • 给他们的父级设置font-size:0;如果里面的子元素需要设置文字大小,再单独设置即可。
  • 浮动也可以解决(后面学)
<!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>
    * {
      margin: 0;
      padding: 0;
    }

    body {
      font-size: 0;
    }

    img {
      width: 300px;
      height: 200px;
      /* font-size: 0; */
    }
  </style>
</head>

<body>
  <img src="./img/1.png" alt="">
  <img src="./img/2.png" alt="">
</body>

</html>

16、overflow属性

  1. overflow属性定义一个内容太大无法适应容器的时候应该怎么做
  2. 设置给被超出的元素
    • visible:默认,内容不会被修剪,而是显示在元素的框外
    • hidden:超出内容被修剪,修剪掉的内容不可见,并且没有滚动条
    • scroll:超出内容被修剪,浏览器显示滚动条方便查看被修剪的内容
    • auto:浏览器定夺,如果内容超出就生成滚动掉,否则不生成
  1. overflow:auto和scroll的区别:
    • auto:是自动生成滚动条,不超出不生成 超出才生成
    • scroll:无论是否超出都会生成滚动条
  1. overflow-x:overflow-y:只控制x和y的超出情况

17、visibility属性:

控制元素显示或者隐藏

  • hidden:控制元素隐藏
    • 保留原来的位置,其他元素的布局没有发生改变
    • 相当于此元素变透明
    • visibility属性是继承的,里边的子元素也全部都继承属性,并且隐藏了
    • 如果给子元素设置visible覆盖,那么子元素可以进行显示
  • visible:让visibility:hidden隐藏的元素显示
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>visibility属性</title>
    <style>
        .box{
            width: 600px;
            height: 400px;
            background: yellow;
        }
        .con1{
            width: 300px;
            height: 100px;
            background-color: pink;
            visibility: hidden;
        }
        .con1 .inner{
            width: 100px;
            height: 50px;
            background-color: #5ab3f4;
            visibility: visible;
        }
        .con2{
            width: 300px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="con1">
            <div class="inner"></div>
        </div>
        <div class="con2"></div>
    </div>
</body>
</html>

18、opacity透明度:

指定了一个元素的透明度

  • 当opacity作用在某一个元素上的时候,把这个元素和里边的内容当成一个整体看待 即使里边的元素没有继承opacity。它也和父级有一样的透明度
  • opacity的取值是 1-0
    • 1代表完全不透明
    • 0代表完全透明
  • 20
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Leaflet中,可以使用zIndexOffset属性来设置图标的z-index值。默认情况下,图标的z-index值为0。通过设置zIndexOffset属性,可以调整图标的z-index值,以避免标签与图标相互遮挡。在给标签添加自定义样式时,可以使用CSS的z-index属性来控制标签的层级关系。\[1\] 另外,Leaflet还提供了API文档和在线例子,可以详细了解Leaflet的各个类的函数和属性,以及使用Leaflet插件的方法。\[2\] 在CSS中,可以使用position属性来设置元素的定位方式。其中,absolute表示绝对定位,完全脱离标准文档流。结合方位词(left、right、top、bottom)一起使用,可以定义元素相对于其包含块的位置。如果没有指定参考,元素将以窗口为参考进行定位;如果定义了参考,元素将以包含块为参考进行定位。\[3\] #### 引用[.reference_title] - *1* [leaflet添加自定义标注且不遮挡点位图标](https://blog.csdn.net/m0_74149462/article/details/130194895)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [leaflet结合Leaflet-Geoman插件实现绘制以及动态配置样式(附源码下载)](https://blog.csdn.net/liguoweioo/article/details/120376461)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [前端学习day07](https://blog.csdn.net/qq_44559185/article/details/123300569)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值