首页 > 其他分享 >CSS-background 背景图片

CSS-background 背景图片

时间:2023-11-30 17:46:12浏览次数:48  
标签:repeat bottom -- top 背景图片 background CSS left

更多CSS进阶: https://www.cnblogs.com/warmNest-llb/p/17866954.html

 

1.背景介绍

  元素的背景属性:

    background 简写属性,作用是将背景属性设置在一个声明中。     background-attachment:背景图像是否固定或者随着页面的其余部分滚动。scroll 默认值。 /fixed 当页面的其余部分滚动时,背景图像不会移动。     background-color:设置元素的背景颜色。     background-image:把图像设置为背景。     background-position:设置背景图像的起始位置。属性可以是百分比:%;单位:px ;也可以是 left/right/center/bottom/top 这几个属性值可以两两组合使用,如果只规定了一个关键词,那么第二个值将时"center"。     center--居中。     position方位:是从 x 轴半轴 y 负半轴 的方位。     left/top/right/bottom--左上右下。

  当图片小于盒子时,图片位置默认在左上角。

 

2.背景设置

  ①元素背景属性:
    background 简写属性,作用是将背景属性设置在一个声明中
    background-image:url---设置背景
    background-position:设置图片起始位置(top、bottom、left、right组合使用)
    background-repeat:设置图片是否重复(no-repeat:不重复)
   CSS新增
    background-size:设置背景图大小
    background-cover:扩展图片(不留白)
    background-contain:背景扩展至最大(可能留白)

都在代码里,直接展示。

代码:

/* 盒子1 */
.box1{
    /* 设置一个550*700大小的盒子 */
    width: 550px;
    height: 700px;
    /* ridge--3D垄状边框 */
    border: 10px ridge brown;
    float: left;
    margin-left: 180px;
    /* 将两个背景图片链接放在一个盒子里 */
    /* no-repeat--设置背景图不重复
    right bottom--将图片置于右下角
    left top--将图片置于左上角 */
    background: url(http://img.duoziwang.com/uploads/1512/1-1512232234340-L.jpg) no-repeat left top,
                url(https://img1.baidu.com/it/u=110908691,589273986&fm=253&fmt=auto?w=200&h=200) no-repeat right bottom;
}


.xiantiao{
    margin-left: 20px;
    width: 500px;
    height: 20px;
    border-top: 1px solid black;
    border-bottom: 1px solid black;
    position: relative;
    z-index: -1; /* 设置优先级 */
}


/* 盒子2 */
.box2{
    width: 550px;
    height: 700px;
    /* ridge--3D垄状边框 */
    border: 10px ridge brown;
    float: left;
    background-color: tan;
    position: relative;

}
.box2 .tu1{
    width: 200px;
    height: 200px;
    /* repeat:no-repeat--设置背景图不重复 */
    background-repeat: no-repeat;
    background-image: url(https://img1.baidu.com/it/u=110908691,589273986&fm=253&fmt=auto?w=200&h=200);
    position: absolute;
    left: 350px;
    bottom: 0px;
}
.tu2{
    width: 190px;
    height: 190px;
    /* repeat:no-repeat--设置背景图不重复 */
    background-repeat: no-repeat;
    background-image: url(http://img.duoziwang.com/uploads/1512/1-1512232234340-L.jpg);
    position: absolute;
    left: 0px;
    top: 0px;
}
.xiantiao1{
    margin-left: 20px;
    width: 500px;
    height: 20px;
    border-top: 1px solid black;
    border-bottom: 1px solid black;
}

 

 

视图:

  

 

..图片百度,侵权劝删

 

标签:repeat,bottom,--,top,背景图片,background,CSS,left
From: https://www.cnblogs.com/warmNest-llb/p/17867898.html

相关文章

  • CSS
    1、文字超出用省略号...鼠标悬停显示全部文字<divstyle="font-size:12px;margin-top:30px;padding:10px20px;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:4;hei......
  • css三角形
    https://blog.csdn.net/weixin_43951592/article/details/127442235https://blog.csdn.net/m0_60237095/article/details/130076471 ......
  • 每日一练:css关键词:inherit、initial、revert、unset解释
    1、inherit(继承)inherit关键词用于将一个属性值设置为其父元素的相同属性值。它是一种实现样式继承的方式,使子元素继承父元素的样式属性。如果父元素没有明确定义该属性,子元素将继承到该属性的默认值。这个关键词通常用于处理文本属性,如文本颜色、字体等。<div><p>这是......
  • Golang - context.TODO()和context.Background()的区别
    context.Background():上下文的默认值(创建上下文的默认起点),这个函数返回一个空context,返回值就是根节点,这只能用于最高等级(在main函数、初始化或顶级请求处理中),因为所有其他的上下文都应该从它衍生(Derived)出来context.TODO():通常用作占位符或临时解决方案,只在不确定应该使用哪种上......
  • Why I see scss file in my chrome inspector?
    WhyIseescssfileinmychromeinspector?BecausetherearemapfilesinyourCSSfolderlike*.css.mapand*.scss.map.Itbasicallyreversemapstheglobal.csswhichisbeingusedbythebrowsertotheconstituent.scssfiles.Theyaretherebecause......
  • 关于CSS3的学习
    CSS的普通选择器:标签选择器、id选择器、类选择器、通用选择器(*)、分组选择器(将具有相同样式的元素放在一起,之间用","分隔)。注:类名和id名不能以数字开头。 rgba是rgb颜色的扩展,前三个值为三原色和rgb一致,第四个值是设置透明度的,1为完全不透明,0是完全透明为白色。hex颜色是用......
  • 记录一下vue如果全局引入scss变量
    开始首先一些普通的css,可以在App.vue中引入然后项目中会经常用到一些功能型的scss,比如mixin,和函数等,这个时候在main.js和app.vue是无效的。首先查看自己的sass和sass-loader版本,注意sass-loader的安装版本,如果是v8的版本使用prependDatea,以上的版本使用additionalData(翻......
  • css同时满足多个class写法
    css同时满足多个class的写法(取交集).el-menu-item.is-active{border-left:5px;border-color:#039EFD;border-right-style:solid;background-color:#D8F4FE;}css满足其中一个class的写法(取并集).el-menu-item,.is-active{border-left:5px;border-co......
  • CSS-position 定位
     1.介绍css定位属性允许对元素进行定位改变其在页面的位置。css有三种基本定位机制:普通流、浮动和绝对定位。普通流的元素的位置由元素在html中的位置决定。 2.定位属性设置偏移量:left、right、top、bottom(左、右、上、下)3.定位方式①静态定位(static):(很少用)......
  • 直播平台制作,css之如何清除浮动
    直播平台制作,css之如何清除浮动<styletype="text/css">  li{    list-style:none;    height:100px;    width:100px;    float:left;    background:red;    margin-left:20px;  }     .father:after,......