iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > node.js >HTML与CSS中背景相关属性怎么用
  • 579
分享到

HTML与CSS中背景相关属性怎么用

2024-04-02 19:04:59 579人浏览 安东尼
摘要

小编给大家分享一下html与CSS中背景相关属性怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!   一.背景尺寸属性

小编给大家分享一下htmlCSS中背景相关属性怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

  一.背景尺寸属性

  1.什么是背景尺寸属性

  背景尺寸属性是css3中新增的一个属性,专门用于设置背景图片大小

  background-size:xxxx;

  取值:

  1.具体像素>>background-size:200px100px;

  2.百分比>>background-size:100%80%;

  3.宽度等比拉伸>>background-size:auto100px;

  4.高度等比拉伸>>background-size:100pxauto;

  5.cover>>background-size:cover;

  5.1告诉系统图片需要等比拉伸

  5.2告诉系统图片需要拉伸到宽度<a>和</a>高度都填满元素

  6.contain>>background-size:contain;

  6.1告诉系统图片需要等比拉伸

  6.2告诉系统图片需要拉伸到宽度<a>或</a>高度都填满元素(<a>只保证一边填满</a>)

  background-size

  二.背景图片定位区域属性

  <a>background-origin</a>:告诉系统背景图片从什么区域开始显示,默认情况下就是从padding区域开始显示;

  取值:

  1.<a>padding-box</a>:默认值>>background-origin:padding-box;告诉系统背景图片从什么区域开始显示,默认情况下就是从padding区域开始显示;

  2.<a>border-box</a>>>background-origin:border-box;从border位置开始

  3.<a>content-box</a>>>background-origin:content-box;从content位置开始

  <htmllang="en"><head><metacharset="UTF-8"><title>113-背景图片定位区域属性</title><style>*{margin:0;padding:0;}ulli{list-style:none;float:left;width:100px;height:100px;text-align:center;line-height:100px;border:20pxdashed#000;padding:50px;margin-left:20px;background:url("images/dog.jpg")no-repeat;}ulli:nth-child(2){background-origin:padding-box;}ulli:nth-child(3){background-origin:border-box;}ulli:nth-child(4){background-origin:content-box;}</style></head><body><ul><li>默认</li><li>padding</li><li>border</li><li>content</li></ul></body></html>

  背景图片定位区域属性

  三.背景绘制区域属性

  <a>background-clip:xxx;</a>背景绘制区域属性是专门用于指定从哪个区域开始绘制背景的,默认情况下会从border区域开始绘制背景

  <htmllang="en"><head><metacharset="UTF-8"><title>114-背景绘制区域属性</title><style>*{margin:0;padding:0;}ulli{list-style:none;float:left;width:100px;height:100px;text-align:center;line-height:100px;border:20pxdashed#000;padding:50px;margin-left:20px;background:redurl("images/dog.jpg")no-repeat;}ulli:nth-child(2){background-clip:padding-box;}ulli:nth-child(3){background-clip:border-box;}ulli:nth-child(4){background-clip:content-box;}</style></head><body><ul><li>默认</li><li>padding</li><li>border</li><li>content</li></ul></body></html>

  背景绘制区域属性(红色为绘制区域)

  四.多重背景图片

  <a>先添加的背景图片会盖住后添加的背景图片</a>

  元素c3之后可以设置多张背景图片

  多张背景图片之间用逗号隔开即可

  background:url("images/animal1.png")no-repeatlefttop,url("images/animal2.png")no-repeatrighttop,url("images/animal3.png")no-repeatleftbottom;

  注意点:

  先添加的背景图片会盖住后添加的背景图片

  background:url("images/animal1.png")no-repeatlefttop,url("images/animal2.png")no-repeatrighttop,url("images/animal3.png")no-repeatleftbottom,url("images/animal4.png")no-repeatrightbottom,url("images/animal5.png")no-repeatcentercenter;

  建议在编写多重背景时拆开编写

  background-image:url("images/animal1.png"),url("images/animal2.png"),url("images/animal3.png");background-repeat:no-repeat,no-repeat,no-repeat;background-position:lefttop,righttop,leftbottom;

  完整代码如下:

  <htmllang="en"><head><metacharset="UTF-8"><title>115-多重背景图片</title><style>*{margin:0;padding:0;}p{width:500px;height:500px;border:1pxsolid#000;margin:0auto;background-image:url("images/animal1.png"),url("images/animal2.png"),url("images/animal3.png");background-repeat:no-repeat,no-repeat,no-repeat;background-position:lefttop,righttop,leftbottom;}</style></head><body><p></p></body></html>

  多重背景图片

  四.多重背景图片联系

  <a>先添加的背景图片会盖住后添加的背景图片</a>

  <htmllang="en"><head><metacharset="UTF-8"><title>116-多重背景图片-练习</title><style>*{margin:0;padding:0;}p{width:600px;height:190px;border:1pxsolid#000;margin:100pxauto;background-image:url("images/bg-plane.png"),url("images/bg-sun.png"),url(images/bg-clouds.png);background-repeat:no-repeat,no-repeat,no-repeat;background-size:50px50px,50px50px,autoauto;background-position:50px150px,400px50px,0px0px;animation:move10slinear0sinfinitenORMal;}@keyframesmove{from{background-position:50px150px,400px50px,0px0px;}to{background-position:500px-150px,400px50px,-600px0px;}}</style></head><body><p></p></body></html>

HTML与CSS中背景相关属性怎么用HTML与CSS中背景相关属性怎么用

以上是“HTML与CSS中背景相关属性怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网node.js频道!

--结束END--

本文标题: HTML与CSS中背景相关属性怎么用

本文链接: https://www.lsjlt.com/news/90931.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作