css初学者第四天

发布于:2025-08-09 ⋅ 阅读:(14) ⋅ 点赞:(0)

<1>snipaste工具的使用

snipaste是一个简单但强大的截图工具,也可以让你将截图贴回屏幕上。

常用的快捷方式:

1、F1可以截图,同时测量大小,设置箭头 书写文字等

2、F3在桌面置顶显示

3、点击图片,alt可以取色(按shift可以切换取色模式)

4、按下esc可以取消图片显示


简洁版小米侧边栏案例

<!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>
    div {
      width: 200px;
      height: auto;
      background-color:rgb(61, 60, 60);

    }
    a {
      text-decoration: none;
      font-size: 14px;
      line-height: 30px;
      color: white;
      display: block;
      margin: 0  auto; 
      padding: 0 20px;
    }
    a:hover {
      background-color: orange;
    }
  </style>
</head>
<body>
  <div>
    <a href="#">手机 电话卡</a>
    <a href="#">电视 盒子</a>
    <a href="#">笔记本 平板</a>
    <a href="#">出行 穿戴</a>
    <a href="#">智能 路由器</a>
    <a href="#">健康 儿童</a>
    <a href="#">耳机 音响</a>
  </div>
</body>
</html>

效果图:

<2>css背景

通过css背景属性,可以给页面元素添加背景样式。

背景属性可以设置背景颜色、背景图片、背景平铺、背景图片位置、背景图像固定等。

2.1 背景颜色

background-color属性定义了元素的背景颜色,默认情况下是透明色。

2.2 背景图片

background-image属性描述了元素的背景图像。实际开发常见于logo或者一些装饰性的小图片或者是超大的背景图片,优点是非常便于控制位置(精灵图也是一种运用场景)

background-image : none | url(url)

2.3 背景平铺

如果需要再html页面上对背景图像进行平铺,可以使用background-repeat属性。

background-repeat : repeat: repeat | no-repeat | repeat-x | repeat-y

2.4 背景图片位置

利用background-position属性可以改变图片在背景中的位置。

background-position: x y;

参数代表的意思是:x坐标和y坐标。可以用方位名词或者精确单位。

参数值 说明
length 百分数 | 由浮点数字和单位标识符组成的长度值
position top | center | bottom | left | center | right 方位名词

2.4.1 参数是方位名词

-如果指定的两个值都是方位名词,则两个值前后顺序无关,比如 left top 和 top left效果一致

-如果只指定了一个方位名词,另一个值省略,则第二个值默认居中对齐

2.4.2 参数是精确单位

-如果参数值是精确坐标,那么第一个肯定是x坐标,第二个一定是y坐标

-如果只指定一个数值,那该数值一定是x坐标,另一个默认垂直居中

2.4.3 参数是混合单位

-如果指定的两个值是精确单位和方位名词混合使用,则第一个值是x坐标,第二个值是y坐标

如:

background-position: 20px center;

  2.5 背景图像固定(背景附着)

background-attachment属性设置背景图像是否固定或者随页面的其余部分滚动

background-attachment后期可以制作视觉滚动的效果。

参数 作用
scroll 背景图像是随对象内容滚动
fixed 背景图像固定

2.6 背景属性

为了简化背景属性的代码,我们可以将这些属性合并简写在同一个属性background中,当使用简写属性时,没有特定的书写顺序,一般习惯约定顺序为:

background:背景颜色 背景图片地址 背景平铺 背景图像滚动 背景图片位置

如:

background:black url(images/bg.jpg) no-repeat fixed center top;

2.7 背景半透明

语法:

background: rgba(0,0,0,0.3);

最后一个参数的alpha透明度,取值范围在0~1之间

我们习惯把0.3的0省略掉,写为background:rgba(0,0,0,.3);

注意:背景半透明是指盒子北京半透明,盒子里面的内容不受影响


五彩导航案例

<!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>
    div {
      display: inline;
      width: 600px;
      height: 100px;
    }

    .red {
      /* 背景图片设置 */
      background-image: url('images/气泡.jpg');
      background-color: #d3525e;
      background-blend-mode: soft-light;
      /* 改用柔光混合模式 */
      background-repeat: no-repeat;
      background-size: 100% 100%;
      /* 图片完全覆盖元素 */
      background-position: center;
      /* 图片居中对齐 */

      /* 元素尺寸设置 */
      width: 80px;
      height: 56px;

      /* 文字样式设置 */
      color: white;
      font-size: 10px;
      line-height: 56px;
      /* 行高等于容器高度实现垂直居中 */
      text-align: center;

      display: inline-block;
      transform: translateY(-2px);
      /* 微调文字位置 */
    }

    .blue {
      background-image: url('images/气泡.jpg');
      background-color: #369ec8;
      background-blend-mode: soft-light;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      background-position: center;

      width: 80px;
      height: 56px;

      color: white;
      font-size: 10px;
      line-height: 56px;
      text-align: center;

      display: inline-block;
      transform: translateY(-2px);
    }

    .purple {
      background-image: url('images/气泡.jpg');
      background-color: #8150ca;
      background-blend-mode: soft-light;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      background-position: center;

      width: 80px;
      height: 56px;

      color: white;
      font-size: 10px;
      line-height: 56px;
      text-align: center;

      display: inline-block;
      transform: translateY(-2px);
    }

    .pink {
      background-image: url('images/气泡.jpg');
      background-color: #c154c8;
      background-blend-mode: soft-light;
      background-repeat: no-repeat;
      background-size: 100% 100%;
      background-position: center;

      width: 80px;
      height: 56px;

      color: white;
      font-size: 10px;
      line-height: 56px;
      text-align: center;

      display: inline-block;
      transform: translateY(-2px);
    }

        /* 添加鼠标悬停效果 */
    span:hover {
      background-blend-mode: multiply;
      /* 悬停时改变混合模式 */
      cursor: pointer;
      /* 显示手型光标 */
    }
  </style>
</head>

<body>
  <div>
    <span class="red">五彩导航</span>
    <span class="blue">五彩导航</span>
    <span class="purple">五彩导航</span>
    <span class="pink">五彩导航</span>
  </div>
</body>

</html>


网站公告

今日签到

点亮在社区的每一天
去签到