当前位置: 首页 > news >正文

CSS学习6

CSS背景

  • 一、背景颜色和图片
  • 二、背景位置
  • 三、背景附着
  • 四、背景简写
  • 五、背景透明
  • 六、背景缩放
  • 七、多背景
  • 八、凹凸文字
  • 九、导航栏例子

一、背景颜色和图片

  • background-color: pink; 背景颜色
  • backgroundoimage: url(##.jpg); 背景图片
  • background-repeat: 平铺 repeat-x横向平铺,repeat-y纵向平铺;

平铺不到的地方显示背景颜色。

<html><head><style>div {width: 400px;height: 500px;background-color: pink;background-image: url(1.jpg);background-repeat: no-repeat;}</style></head><body><div></div></body>
</html>

二、背景位置

background-position: 更改背景图片位置,可以写两种值:

  • position包括top,center,bottom,left,right;顺序无所谓;
  • length写x和y坐标,以页面左上角为0点,向右为x轴,向下为y轴;
  • 实际应用的时候也可以两种混搭: 10px center;
<html><head><style>div {background-color: pink;background-imgage: url(1.jpg);background-repeat: no-repeat;background-position: left top; /*默认左上角*//*如果方位名词只写一个,另一个默认center*/background-position: 10px 30px;/*精确单位,第一个值是x坐标,第二个值是y坐标*/}</style></head><body><div></div></body>
</html>

三、背景附着

设置背景内容随对象内容滚动还是固定。

  • scroll; 背景内容随内容滚动
  • fixed; 背景内容固定
<html><head><style>body {background-color: pink;background-imgage: url(1.jpg);background-repeat: no-repeat;background-position: left top;background-attachment: scroll;	}</style></head><body><div></div></body>
</html>

四、背景简写

background: 背景颜色 背景图片 背景平铺 背景滚动 背景位置。

<html><head><style>body {/*background-color: pink;background-imgage: url(1.jpg);background-repeat: no-repeat;background-position: left top;background-attachment: scroll;	*/background: #000 url(#.png) no-repeat fixed center -25px;}</style></head><body><div></div></body>
</html>

五、背景透明

文字半透明:color: rgba(0,0,0,0.2);
背景半透明:background: rgba(0,0,0,0.3);

<html><head><style>body {background: #000 url(#.png) no-repeat fixed center -25px;}div {height: 400px;background: rgba(0,0,0,0.3);}</style></head><body><div></div></body>
</html>

六、背景缩放

background-size: 设置背景图片缩放

  • 设置宽高精确单位,尽量只改一个值防止缩放失真
  • 设置百分比
  • cover自动缩放占满,溢出的部分会被隐藏,使用最多
  • contain自动缩放,高宽有一个和背景一样大停止,保持图片完整性但是会有裸露部分

我们插入的图片img直接用width和height设置

<html><head><style>div {height: 400px;background: hotpink url(#.jpg) no-repeat;background-size: 100px;background-size: 50%; /*缩放为原来的一半*/background-size: cover;background-size: contain;}</style></head><body><div></div></body>
</html>

七、多背景

background: # # # #, # # #;用逗号分割设置多个背景图

  • 一个元素设置多重背景图片
  • 每组属性用逗号分隔
  • 如果存在重叠,前面的背景图会覆盖在后面的背景图上
  • 背景颜色通常定义在最后一组上
<html><head><style>div {height: 400px;background: url(#.jpg) no-repeat left top , url(##.jpg) no-repeat left hotpink;}</style></head><body><div></div></body>
</html>

八、凹凸文字

<html><head><style>body {background-color: #ccc;}div {color: #ccc;font: 700 60px "微软雅黑";}div:first-child {text-shadow: 1px 1px 1px #000, -1px -1px 1px #fff;}div:last-child {text-shadow: -1px -1px 1px #000, 1px 1px 1px #fff;}</style></head><body><div>凸起的文字</div><div>凹下的文字</div></body>
</html>

九、导航栏例子

文本装饰:text-decoration

  • none 无
  • underline 下划线,链接默认
  • overline 上划线
  • line-through 删除线
<html><head><style>a {width: 100px;height: 50px;background-color: orange;display: inline-block;text-align: center;line-height: 50px; /*行高等于盒子高度,文字居中*/color: #fff;font-size: 20px;text-decoration: none;}a:hover { /*鼠标经过*/background: url(#.png) no-repeat;}</style></head><body><a href="#">qwe</a><a href="#">asd</a></body>
</html>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • CSS中 特殊类型的选择器 伪元素如何使用
  • python文件自动化(4)
  • XMind v24 激活,简单一键激活
  • Spring、SpringMVC、SpringBoot都是什么,有什么区别
  • TinyWebSever源码逐行注释()_简单代码的整合
  • 将 x 减到 0 的最小操作数
  • 视觉语言模型(VLMs)知多少?
  • 【2024】MySQL库表基本操作
  • 从 CRX 文件安装 Chrome 扩展程序
  • 安卓13带有系统签名的应用不能正常使用webview 调用webview失败 系统应用app apk
  • 突破代码:克服编程学习中的挫折感
  • 创建一个Oracle版本的JDK的Docker镜像
  • C++笔记15•数据结构:二叉树之二叉搜索树•
  • STM32 系列MCU 开发利器 STM32CubeIDE
  • Pandas_[‘index‘]_is_not_found_in_axis
  • [PHP内核探索]PHP中的哈希表
  • 《深入 React 技术栈》
  • 【vuex入门系列02】mutation接收单个参数和多个参数
  • 【从零开始安装kubernetes-1.7.3】2.flannel、docker以及Harbor的配置以及作用
  • 08.Android之View事件问题
  • css的样式优先级
  • ECMAScript6(0):ES6简明参考手册
  • linux安装openssl、swoole等扩展的具体步骤
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • Mithril.js 入门介绍
  • React组件设计模式(一)
  • Spring-boot 启动时碰到的错误
  • vue中实现单选
  • Wamp集成环境 添加PHP的新版本
  • Web标准制定过程
  • 不上全站https的网站你们就等着被恶心死吧
  • 如何在 Tornado 中实现 Middleware
  • 数据科学 第 3 章 11 字符串处理
  • 曜石科技宣布获得千万级天使轮投资,全方面布局电竞产业链 ...
  • ​虚拟化系列介绍(十)
  • #FPGA(基础知识)
  • #Linux(make工具和makefile文件以及makefile语法)
  • #pragma预处理命令
  • #Ubuntu(修改root信息)
  • #Z2294. 打印树的直径
  • $con= MySQL有关填空题_2015年计算机二级考试《MySQL》提高练习题(10)
  • (3)Dubbo启动时qos-server can not bind localhost22222错误解决
  • (70min)字节暑假实习二面(已挂)
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (M)unity2D敌人的创建、人物属性设置,遇敌掉血
  • (八)光盘的挂载与解挂、挂载CentOS镜像、rpm安装软件详细学习笔记
  • (不用互三)AI绘画:科技赋能艺术的崭新时代
  • (附源码)ssm高校升本考试管理系统 毕业设计 201631
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (三)c52学习之旅-点亮LED灯
  • (四十一)大数据实战——spark的yarn模式生产环境部署
  • (学习总结16)C++模版2
  • (原)记一次CentOS7 磁盘空间大小异常的解决过程
  • * 论文笔记 【Wide Deep Learning for Recommender Systems】
  • .bat文件调用java类的main方法