css中与背景相关的属性有哪些

发布时间:2022-03-01 15:19:41 作者:小新
来源:亿速云 阅读:138

这篇文章给大家分享的是有关css中与背景相关的属性有哪些的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

  1、css背景属性之为内容设置背景色:background-color;

  属性:

  颜色;

  inherit;继承父级样式

  box.html

  <!doctypehtml>

  <html>

  <head>

  <matecharset="utf-8">

  <title>背景</title>

  <linkhref="box.css"type="text/css"rel="stylesheet">

  </head>

  <body>

  <p为内容设置背景色:background-color;</p>

  </body>

  </html>

  box.css

  body{

  background-color:#123456;

  }

  2、css背景属性之为内容设置背景为图片background-image:url();

  box.css

  body{

  background-color:#123456;

  background-image:url(image.png);

  }

  3、css背景属性之固定背景图片background-attachment

  (在CSS中使用background-attachment属性可以将图片固定在浏览器上,如果拖动滚动条,背景图片不会随着网页内容的滚动而滚动,像文字浮在图片上)

  属性值:

  scroll;背景图片随内容滚动,默认值

  fixed;背景图片固定,不随内容滚动

  inherit;继承父类样式

  box.css

  body{

  background-color:#123456;

  background-image:url(image.png);

  background-attachment:fixed;

  font-size:45px;

  }

  4、css背景属性之背景图片平铺background-repeat;

  属性值:

  repeat;平铺背景图片;默认

  no-repeat;不平铺图片;

  repeat-x;在水平方向平铺

  repert-y;在竖直方向平铺

  box.css

  body{

  background-color:#123456;

  background-image:url(image.png);

  background-attachment:fixed;

  font-size:45px;

  background-repeat:repeat-y;

  }

  5、css背景属性之背景图片定位background-position

  属性值:

  top;顶部

  center;中间

  bottom;底部

  right;右边

  left;左边

  inherit;继承父类样式

  样式:

  xxxpx,xxxpx;

  xxx%,xxx%;

  xxxpx,top;

  box.css

  body{

  background-color:#123456;

  background-image:url(image.png);

  background-attachment:fixed;

  font-size:45px;

  background-repeat:no-repeat;

  background-position:left;

  }

感谢各位的阅读!关于“css中与背景相关的属性有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. CSS背景相关知识
  2. HTML与CSS中背景相关属性有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css

上一篇:HTML5表格怎么构建

下一篇:css怎么使用opacity属性给背景图片加透明度

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》