网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

6个CSS背景图片设置的方法技巧-创新互联

这篇文章将为大家详细讲解有关6个CSS背景图片设置的方法技巧,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

十年的剑河网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整剑河建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联建站从事“剑河网站设计”,“剑河网站推广”以来,每个客户项目都认真落实执行。

1.如何将背景图像完美地适合视口

body {
  background-image: url('https://images.unsplash.com/photo-1573480813647-552e9b7b5394?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2253&q=80');
  background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
}

background-attachment设置背景图像是否固定或者随着页面的其余部分滚动。

6个CSS背景图片设置的方法技巧

2.如何在CSS中使用多个背景图片

body {
  background-image: url(https://image.flaticon.com/icons/svg/748/748122.svg), url(https://images.unsplash.com/photo-1478719059408-592965723cbc?ixlib=rb-1.2.1&auto=format&fit=crop&w=2212&q=80);
  background-position: center, top;
  background-repeat: repeat, no-repeat;
  background-size: contain, cover;
}

6个CSS背景图片设置的方法技巧

3.如何创建三角背景图像

当我们想展示某些完全不同的选择(例如白天和黑夜或冬天和夏天)时。

这是通过为整个视口创建两个div来完成的,然后需要向它们两个都添加背景图像,然后,第二个div需要一个clip-path属性才能创建三角形。


  
  
body {   margin: 0;   padding: 0; } div {   position: absolute;   height: 100vh;   width: 100vw; } .day {   background-image: url("https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2613&q=80");   background-size: cover;   background-repeat: no-repeat; } .night {   background-image: url("https://images.unsplash.com/photo-1493540447904-49763eecf55f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2250&q=80");   background-size: cover;   background-repeat: no-repeat;   clip-path: polygon(100vw 0, 0% 0vh, 100vw 100vh); }

clip-path属性创建一个裁剪区域,该区域设置应显示元素的哪一部分。区域内的部分显示,区域外的隐藏。

6个CSS背景图片设置的方法技巧

4.如何在我的背景图像上添加渐变叠加、

想在图像上放置一些文本但背景太浅文本显示不清晰时,它会很有用,同时它也可以改善图像本身

body {
  background-image: 
    linear-gradient(4deg, rgba(38,8,31,0.75) 30%, rgba(213,49,127,0.3) 45%, rgba(232,120,12,0.3) 100%),
    url("https://images.unsplash.com/photo-1503803548695-c2a7b4a5b875?ixlib=rb-1.2.1&auto=format&fit=crop&w=2250&q=80");
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position: center
}

6个CSS背景图片设置的方法技巧

5.如何制作网格背景图片

使用CSS网格和CSS背景图像创建一个不错的背景图像



  
                                            
body {
 margin: 0;
  padding: 0;
}

.container {
  position: absolute;
  width: 100%;
  height: 100%;
  background: black;
  display: grid;
  grid-template-columns: 25fr 30fr 40fr 15fr;
  grid-template-rows: 20fr 45fr 5fr 30fr;
  grid-gap: 20px;
  .item_img {
    background-image: url('https://images.unsplash.com/photo-1499856871958-5b9627545d1a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2207&q=80');
    background-repeat: no-repeat;
    background-position: center;
    background-attachment: fixed;
    background-size: cover;
  }
}

6个CSS背景图片设置的方法技巧

6.如何将背景图像设置为文本颜色

通过将背景图像与背景剪辑配合使用,可以实现背景图像对文字的优美效果。在某些情况下,它可能非常有用,尤其是当您想创建一个较大的文本标题但又不如普通颜色那么枯燥时。


  

Hello world!

body {   display: flex;   align-items: center;   justify-content: center;   flex-direction: column;   width: 100%;   text-align: center;   min-height: 100vh;   font-size: 120px; } h2 {    background-image: url("https://images.unsplash.com/photo-1462275646964-a0e3386b89fa?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2600&q=80");   background-clip: text;   -webkit-background-clip: text;   color: transparent; }

6个CSS背景图片设置的方法技巧

关于“6个CSS背景图片设置的方法技巧”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


分享文章:6个CSS背景图片设置的方法技巧-创新互联
文章分享:http://bjjierui.cn/article/dsgoso.html