背景滚动(background attachment)

CSS提供的background-attachment属性用于设置背景图像的固定方式,比如是否随着页面滚动。简单来说,background-attachment用于指明背景图片的位置是固定于视口,还是随着包含块移动的。可理解为定义背景图片随滚动轴的移动方式。

background-attachment: scroll | fixed | local | inherit;
属性值 描述
scroll 默认值,背景像随着页面其它部分滚动而滚动,背景相对于元素固定,背景和内容绑定。
fixed 背景不会随着页面的滚动而滚动,背景相对于视口固定,随页面滚动背景不动,相当于背景被设置在body上。
local 背景随着元素内容的滚动而滚动,背景相对于元素内容固定。
inherit 从父元素继承
background-attachment:scroll;

设置background-attachment背景图片是相对于元素自身固定,内容滚动时背景也会跟着滚动,同时附加到元素的border上。当元素设置overflow-hidden:scroll属性后会成为滚动元素,此时设置background-attachment:scroll背景图片将不会随着元素内容的滚动而滚动。

background-attachment:fixed;

设置background-attachment:fixed的元素中背景图片是相对于视口(viewport)固定,即使元素拥有滚动条,背景图片也不会随着内容而滚动。

background-attachment:local;

对于滚动元素(设置overflow:scroll属性)设置background-attachment:local后背景图片会随着内容的滚动而滚动。因为背景图片是相对于元素自身内容定位,初始状态为固定,当滚动元素出现滚动条后背景图片将会随着内容而滚动。

工具类 属性
bg-scroll background-attachment:scroll;
bg-fixed background-attachment:fixed;
bg-local background-attachment:local;

背景色(background color)

工具类 属性
bg-transparent background-color:transparent;
bg-current background-color:currentColor;
bg-black background-color:#000;
bg-white background-color:#fff;

背景透明度(background opacity)

工具类 描述
bg-opacity-0 --bg-opacity:0;
bg-opacity-25 --bg-opacity:0.25;
bg-opacity-50 --bg-opacity:0.5;
bg-opacity-75 --bg-opacity:0.75;
bg-opacity-100 --bg-opacity:1;

背景定位(background position)

Tailwind采用bg-{side}方式定义工具类用于设置背景的定位

工具类 描述
bg-top background-position:top;
bg-left-top background-position:left top;
bg-right-top background-position:right top;
bg-left background-position:left;
bg-center background-position:center;
bg-right background-position:right;
bg-bottom background-position:bottom;
bg-left-bottom background-position:left bottom;
bg-right-bottom background-position:right bottom;

背景大小(background size)

background-size: auto | cover | contain;
属性值 描述
auto 默认值,保持背景图片原始宽度和高度。
cover 将背景图片缩放,若图片本身大于容器则缩小到合适宽高以适应容器。
contain 将背景图片缩小以在容器中显示完整图片,若容器宽度于背景图片不一致时会出现留白。

当图片大小超过容器大小时,cover属性值会对背景图片进行裁剪,所以一般会配置background-position属性来决定显示图片内容的位置。

contain属性会将图片缩小以在容器中显示完整图片,多数情况下由于容器宽高比例与图片比例不同,因此造成图片与容器上下或左右留白的情况。

covercontain的区域在于,cover会按照背景图片最长边来按比例放大或缩小,contain则会按照背景最短边按比例放大或缩小。

工具类 属性
bg-auto background-size:auto
bg-cover background-size:cover
bg-contain background-size:contain
position-size

<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet"><div class="container mx-auto my-4 p-4 text-center flex flex-row jutify-between"><div class="bg-gray-100 rounded overflow-hidden border m-2 w-1/2"><div class="h-48 w-full bg-center bg-cover bg-no-repeat" style="background-image:url('http://source.unsplash.com/800x800')"></div>cover</div><div class="bg-gray-100 rounded overflow-hidden border m-2 w-1/2"><div class="h-48 w-full bg-center bg-contain bg-no-repeat" style="background-image:url('http://source.unsplash.com/800x800')"></div>contain</div>
</div>

背景重复(background repeat)

background-repeat属性用于设置是否及如何重复背景图片,即定义背景图片的平铺模式。背景图片会从原图开始重复,原图由background-image定义,并根据background-position放置。

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

CSS3为background-repeat新增了roundspace两个属性值

  • round 背景图片自动缩放自导适应填满整个容器
  • space 背景图片以相同间距平铺且填充整个容器或某个方向
工具类 属性
bg-repeat background-repeat:repeat;
bg-no-repeat background-repeat:no-repeat;
bg-repeat-x background-repeat:repeat-x;
bg-repeat-y background-repeat:repeat-y;
bg-repeat-round backgound-repeat:round;
bg-repeat-space background-repeat:space;
repeat

<div class="bg-gray-100 rounded overflow-hidden border m-2"><div class="h-48 w-full bg-center bg-repeat-space" style="background-image:url('http://source.unsplash.com/100x100')"></div>center repeat space
</div><div class="bg-gray-100 rounded overflow-hidden border m-2"><div class="h-48 w-full bg-center bg-repeat-round" style="background-image:url('http://source.unsplash.com/100x100')"></div>center repeat round
</div>

http://www.taodudu.cc/news/show-4582792.html

相关文章:

  • CSS库 Tailwind
  • TailWind 使用指南
  • Tailwind Size
  • CSS Tailwind
  • tailWindCSS
  • Tailwind Typographic
  • Tailwind 初识
  • Tailwind教程1 - 开始使用
  • Tailwind 真香
  • vue3.2之 Tailwind CSS
  • Tailwind教程2 - 基础样式
  • 学习Vue3 第三十四章(Vue3集成Tailwind CSS)
  • 船说CMS模板 - 笔趣阁自适应模板
  • Python爬虫爬取笔趣阁小说
  • 爬虫实战|从笔趣阁爬取书籍并简单保存
  • 1.4 爬虫-笔趣阁获取小说例子
  • Python爬虫--笔趣阁小说爬取
  • xpath爬取笔趣阁小说
  • 初学爬虫-笔趣阁爬虫
  • 1.python爬取笔趣阁小说
  • python3爬取笔趣阁小说
  • java爬虫爬取笔趣阁小说
  • python爬取小说爬取_用python爬取笔趣阁小说
  • 用python爬取笔趣阁小说并分章节保存到本地
  • python下载笔趣阁小说生成txt文档
  • 爬虫练习-爬取笔趣阁小说
  • python3+正则(re)增量爬虫爬取笔趣阁小说( 斗罗大陆IV终极斗罗)
  • 学计算机和电子信息工程那个更好找工作,电子信息工程专业毕业月薪一般是多少 好不好找工作...
  • 同感,在另外一个小华为待过,也差不多是这样的
  • 硬件开发规范化管理_华为硬件工程师手册_笔记1

Tailwind Background相关推荐

  1. Tailwind Spacing

    单位(size) Tailwind间距单位采用rem,rem是相对于HTML的根元素<html>标签而言的,只需在根元素确定一个参考值,即可计算出不同rem的大小. html{ font- ...

  2. Tailwind Border

    边框半径(border radius) border-redius属性用于为元素设置圆角边框,可使用border-*-radius设置四个方位的圆角.圆角的设置是通过使用半径实现的,当使用一个半径时可 ...

  3. Tailwind Input

    基础输入框 无边框 无边框输入框主要使用了shadow阴影,适合在有底色的环境中使用. 无边框 <input type="text" class="relative ...

  4. Tailwind Base

    添加基础样式 - 使用Tailwind添加全局的基础样式 全局基础样式是样式表开头的样式,用于为基础HTML元素设置有效的默认值,或应用自定义重置样式. Tailwind包括一组实用的基础样式集称为p ...

  5. Tailwind Button

    按钮组 input group 源代码查看地址 https://codepen.io/junchow/pen/dyGowYg?editors=1000 按钮组是由多个按钮水平排列而成,实现方式可分为两 ...

  6. Hello Blazor:(2)集成Tailwind CSS续——nuget包方式

    前段时间,写了一篇"Blazor如何集成Tailwind CSS"的文章.但是操作起来比较麻烦,又是命令行,又是要修改一大堆配置. 后来,我又找到一个更简单的方法. 实现方式 新建 ...

  7. Hello Blazor:(2)集成Tailwind CSS

    Blazor默认集成了bootstrap,对于我这种后端出身,对CSS一知半解的.NET开发人员来说,使用起来还是有一定难度的. 好不容易才学到点皮毛,结果前端人员居然告诉我,bootstrap已经过 ...

  8. tailwind css_什么是Tailwind CSS,如何将其添加到我的网站或React App中?

    tailwind css CSS is a technology that can be your best or worst friend. While it's incredibly flexib ...

  9. Tailwind CSS

    Tailwind CSS Tailwind CSS是一个实用程序优先的 CSS 框架,用于快速构建自定义用户界面. Useful Links 传奇:官方资源 Website - 官方 Tailwind ...

最新文章

  1. 【Qt中文手册】QSortFilterProxyModel
  2. 使用ckeditor
  3. 冲刺第一天 12.29 SAT
  4. 关于vue-cli创建项目(小白)(2)mock数据
  5. 使用 SAP Business Application Studio 开发 Vue 应用
  6. 使用pm2启动Node和Vue项目教程
  7. web前端(12)—— 页面布局2
  8. java基础常问面试题,面试必问
  9. (17)Verilog时钟与复位激励-基本语法(五)(第4天)
  10. STM32出现HardFault故障的解决方法
  11. java中ping多个ip_在Java中ping多个服务器
  12. 计算机绘图说课视频,机械图识读与计算机绘图说课PPT课件.ppt
  13. codeblocks13.12汉化
  14. 联想从国有企业演变成民营集团揭秘(深度)
  15. DirectX12(D3D12)基础教程(十九)—— 多实例渲染
  16. 微软造的还原精灵EWF(Enhanced Write Filter)
  17. 【LLM大模型】模型和指令微调方法
  18. 量子计算 4 超光速信息传播?密度矩阵与混合态
  19. Light OJ 1256
  20. 漫画描述数字电路之时序电路

热门文章

  1. MySQL RANGE分区
  2. 计算机网络三大必备书,网络十大神书据说都看过的可以成仙
  3. 天猫api接口,天猫详情api接口,天猫优惠券信息api接口,天猫到手价api接口,天猫商品详情接口,可用于行业数据分析,价格监控,竞品分析,品牌维权接口代码对接
  4. 【赛事推荐】ICDAR2023国际学术竞赛,六大OCR未解难题等你来挑战!
  5. 【获奖榜单公布】遇见27岁的Java,分享你的开发者故事
  6. 功能:CO11和CO11N的差异
  7. ABAP CA CO CS等操作符
  8. 施耐德电气推出适用于边缘计算的微型数据中心机柜
  9. pyinstaller打包软件失败的真正原因
  10. 免费服务器AWS免费使用一年详细教程