美文网首页
元素的背景图片

元素的背景图片

作者: 岁月悄然飞逝徒留回忆_54a5 | 来源:发表于2018-10-23 20:01 被阅读0次

background-color
background-color属性用来为元素设置背 景颜色。
需要指定一个颜色值,当指定了一个颜色 以后,整个元素的可见区域都会使用这个 颜色作为背景色。
如果不设置背景颜色,元素默认背景颜色 为透明,实际上会显示父元素的背景颜色
background-image
background-image可以为元素指定背景 图片。
和background-color类似,这不过这里使 用的是一个图片作为背景。
需要一个url地址作为参数,url地址需要指 向一个外部图片的路径
例如:
background-image: url(1.jpg)
background-repeat
background-repeat用于控制背景图片的 重复方式4 。
如果只设置背景图片默认背景图片将会使 用平铺的方式,可以通过该属性进行修改。
可选值:
repeat:默认值,图片左右上下平铺
no-repeat:只显示图片一次,不会平铺
repeat-x:沿x轴水平平铺一张图片
repeat-y:沿y轴水平平铺一张图片
background-position
background-position用来精确控制背景 图片在元素中的位置。
可以通过三种方式来确定图片在水平方向 和垂直方向的起点。
关键字:top right bottom left center
百分比
数值
background-attachment
background-attachment用来设置背景图 片是否随页面滚动。
可选值:
scroll:随页面滚动
fixed:不随页面滚动
background
background是背景的简写属性,通过这个 属性可以一次性设置多个样式,而且样式 的顺序没有要求。
例如:
background: green url(1.jpg) no-repeat center center fixed;

作业购物车

  <!DOCTYPE html>
 <html lang="en">
<head>
       <meta charset="UTF-8">
       <title>xuebi</title>
       <style type="text/css">
        .p1{
               width: 500px;
              height: 300px;
              border:  solid 10px;
            margin: 0 auto;
              position: relative;
                      background-color:yellow;
        

            }
  

        .b{
              width: 47px;
              height: 34px;
              border:  solid 10px;
             position: absolute;
             left: 200px;
              bottom :120px;
        
        
    }
    .b1{
        display: block;
        width: 47px;
        height: 34px;
        line-height: 34px;
        
        background-image: url(image/1.png);
        background-repeat: no-repeat;
        background-position: -8px -339px;

    }
    .b1:hover{
        background-color: blue;
        
        background-position: -59px -339px;
    }
    .b1:active{
        background-color: pink;
        
        background-position: -118px -337px;
    }

</style>
</head>
<body>
 <div class="p1">

         <div class="b"><a href="#" class="b1"></a></div>
</div>
</body>
</html>
image.png

相关文章

  • 4、背景图片

    背景图片 样式名称: background-image 定义元素的背景图片 使用方式:[图片上传中...(1570...

  • CSS&JS一些问题

    实现div横向排列,元素往两边撑, 中间自动撑开空格。在父元素里设置 背景图片自适应div 背景图片自适应 tex...

  • CSS3学习笔记(二)

    background-origin:元素背景图片的原始位置。语法: 参数分别表示背景图片是从边框,内边距(默认值)...

  • 第5章 css与背景相关的样式background

    background-origin 设置元素背景图片的原始起始位置。语法: 参数分别表示背景图片是从边框,还是内边...

  • 背景

    设置背景样式 用background-image:url(图片相对路径);设置背景图片如果背景图片大于元素,默认会...

  • [CSS] background-position:x y;

    将背景图片放到目标元素的相对坐标(x,y)处。目标元素右上,是xy的正方向。

  • background-size contain/cover区别

    background-size:cover; 背景铺满元素 调整背景图片的宽度或高度(较小者),以铺满整个元素 保...

  • 元素的背景图片

    background-colorbackground-color属性用来为元素设置背 景颜色。需要指定一个颜色值,...

  • ios下背景图片不能fixed的bug

    苹果手机里面背景图片的fixed属性会失效,使用:before元素解决

  • Web前端社交账号注册按钮

    元素的分类css的diaplay属性背景图片 背景图片 请点赞!因为你们的赞同/鼓励是我写作的最大动力! 欢迎关注...

网友评论

      本文标题:元素的背景图片

      本文链接:https://www.haomeiwen.com/subject/amtzzftx.html