2025年3月27日 星期四 甲辰(龙)年 月廿六 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Html+Div+Css(前端)

CSS精灵图、背景图片、文字阴影、盒子阴影、过渡、版心与CSS书写顺序

时间:07-14来源:作者:点击数:20
CDSY,CDSY.XYZ

1 精灵图

在这里插入图片描述
在这里插入图片描述
  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <meta http-equiv="X-UA-Compatible" content="IE=edge">
  • <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • <title>Document</title>
  • <style>
  • span {
  • display: inline-block;
  • width: 18px;
  • height: 24px;
  • background-color: pink;
  • background-image: url(./images/taobao.png);
  • /* 背景图位置属性: 改变背景图的位置 */
  • /* 水平方向位置 垂直方向的位置 */
  • /* 想要向左侧移动图片, 位置取负数; */
  • background-position: -3px 0;
  • }
  • b {
  • display: block;
  • width: 25px;
  • height: 21px;
  • background-color: green;
  • background-image: url(./images/taobao.png);
  • background-position: 0 -90px;
  • }
  • </style>
  • </head>
  • <body>
  • <!-- <img src="./images/taobao.png" alt=""> -->
  • <!-- 精灵图的标签都用行内标签 span, b, i -->
  • <span></span>
  • <b></b>
  • </body>
  • </html>

2 背景图片大小

在这里插入图片描述
  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <meta http-equiv="X-UA-Compatible" content="IE=edge">
  • <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • <title>Document</title>
  • <style>
  • .box {
  • width: 400px;
  • height:300px;
  • background-color: pink;
  • background-image: url(./images/1.jpg);
  • background-repeat: no-repeat;
  • /* background-size: 300px; */
  • /* background-size: 50%; */
  • /* 如果图的宽或高与盒子的尺寸相同了, 另一个方向停止缩放 -- 导致盒子可能有留白 */
  • background-size: contain;
  • /* 保证宽或高和盒子尺寸完全相同 , 导致图片显示不全 */
  • /* background-size: cover; */
  • /* 工作中, 图的比例和盒子的比例都是相同的, contain 和cover效果完全相同; */
  • }
  • </style>
  • </head>
  • <body>
  • <div class="box"></div>
  • </body>
  • </html>
在这里插入图片描述

3 文字阴影

在这里插入图片描述

4 盒子阴影

在这里插入图片描述
  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <meta http-equiv="X-UA-Compatible" content="IE=edge">
  • <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • <title>Document</title>
  • <style>
  • .box {
  • width: 200px;
  • height: 200px;
  • background-color: pink;
  • box-shadow: 5px 10px 20px 10px green inset;
  • /* 注意: 外阴影, 不能添加outset, 添加了会导致属性报错 */
  • /* box-shadow: 5px 10px 20px 10px green outset; */
  • }
  • </style>
  • </head>
  • <body>
  • <div class="box"></div>
  • </body>
  • </html>

5 过渡

在这里插入图片描述
  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <meta http-equiv="X-UA-Compatible" content="IE=edge">
  • <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • <title>Document</title>
  • <style>
  • /* 过渡配合hover使用, 谁变化谁加过渡属性 */
  • .box {
  • width: 200px;
  • height: 200px;
  • background-color: pink;
  • /* 宽度200, 悬停的时候宽度600, 花费1秒钟 */
  • /* transition: width 1s, background-color 2s; */
  • /* 如果变化的属性多, 直接写all,表示所有 */
  • transition: all 1s;
  • }
  • .box:hover {
  • width: 600px;
  • background-color: red;
  • }
  • </style>
  • </head>
  • <body>
  • <div class="box"></div>
  • </body>
  • </html>

6 版心

在这里插入图片描述

7 CSS书写顺序

在这里插入图片描述
CDSY,CDSY.XYZ
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门