特定高度的部分的背景图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了特定高度的部分的背景图像相关的知识,希望对你有一定的参考价值。

我真正想要实现的是将背景图像放到特定的高度,就像我有一个包含两个div的部分我给了该部分一个背景图像,这是

    background-image: linear-gradient(-207deg, #0EC573, #0093FF);

现在我要实现的是背景图像覆盖了整个第二个div和第一个div的某些部分

完整的代码

 <section class="company py-4" >
        <div class="container">
            <div class="row">
                    <div class="col-12">
          <div class="mt-5 px-3">
                <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="4000">
                    <ol class="carousel-indicators">
                        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
                    </ol>

                    <div class="carousel-inner">
                        <div class="carousel-item active">
                            <img class="img-fluid" src="{!! asset('images/Company/02.jpg') !!}">
                            <div class="mt-5 ">
                            </div>
                        </div>
                        <div class="carousel-item ">
                            <div class="justify-content-center align-items-center">
                                <img class="img-fluid" src="{!! asset('images/Company/01.jpg') !!}">
                            </div>
                            <div class="mt-5 ">
                            </div>
                        </div>
                        <div class="carousel-item">
                            <img class="img-fluid" src="{!! asset('images/Company/03.jpg') !!}">
                            <div class="mt-5 ">
                            </div>
                        </div>
                        <div class="carousel-item">
                            <img class="img-fluid" src="{!! asset('images/Company/04.jpg') !!}">
                            <div class="mt-5 ">
                            </div>
                        </div>
                    </div>
                  <!--   <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button"data-slide="prev">
                        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                        <span class="sr-only">Previous</span>
                    </a>
                    <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
                        <span class="carousel-control-next-icon" aria-hidden="true"></span>
                        <span class="sr-only">Next</span>
                    </a> -->

                </div>
            </div>            
      </div>
            </div>
        </div>
        <div class="container">
            <div class="row justify-content-center align-items-center">
               <div class="col-12 "> 
                <h1 class="text-left heading">Company</h1>
                <p class="text-left description"> ALL THE DESCRIPTION</p>
                </div>
            </div>
        </div>
    </section>
答案

使用它(参见JSFiddle:https://jsfiddle.net/Lfxja1e5/7/):

 background-size: 100% 70%;
 background-repeat: no-repeat;

**如果你想在底层使用它:

background-position: bottom;

 .company{
      background-image:linear-gradient(-207deg,#0EC573, #0093FF);
     background-size: 100% 70%;
     background-repeat: no-repeat;
      background-position: bottom;
    }
<section class="company py-4" >
            <div class="container d1">
                <div class="row">
                        <div class="col-12">
              <div class="mt-5 px-3">
                    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="4000">
                        <ol class="carousel-indicators">
                            <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
                        </ol>

                        <div class="carousel-inner">
                            <div class="carousel-item active">
                                <img class="img-fluid" src="{!! asset('images/Company/02.jpg') !!}">
                                <div class="mt-5 ">
                                </div>
                            </div>
                            <div class="carousel-item ">
                                <div class="justify-content-center align-items-center">
                                    <img class="img-fluid" src="{!! asset('images/Company/01.jpg') !!}">
                                </div>
                                <div class="mt-5 ">
                                </div>
                            </div>
                            <div class="carousel-item">
                                <img class="img-fluid" src="{!! asset('images/Company/03.jpg') !!}">
                                <div class="mt-5 ">
                                </div>
                            </div>
                            <div class="carousel-item">
                                <img class="img-fluid" src="{!! asset('images/Company/04.jpg') !!}">
                                <div class="mt-5 ">
                                </div>
                            </div>
                        </div>
                      <!--   <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button"data-slide="prev">
                            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                            <span class="sr-only">Previous</span>
                        </a>
                        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
                            <span class="carousel-control-next-icon" aria-hidden="true"></span>
                            <span class="sr-only">Next</span>
                        </a> -->

                    </div>
                </div>            
          </div>
                </div>
            </div>
            <div class="container d2">
                <div class="row justify-content-center align-items-center">
                   <div class="col-12 "> 
                    <h1 class="text-left heading">Company</h1>
                    <p class="text-left description"> ALL THE DESCRIPTION</p>
                    </div>
                </div>
            </div>
        </section>

以上是关于特定高度的部分的背景图像的主要内容,如果未能解决你的问题,请参考以下文章

模糊图像的特定部分

输入特定的全屏部分时,是不是可以更改标题背景?

使用颜色选择器更改片段中edittext的背景颜色

如何增加特定部分中特定单元格的高度

如何在 Flutter 中拉伸图像以适合整个背景(100% 高度 x 100% 宽度)?

在 UITabBar 中设置背景图像的问题