图像背景在另一个容器中

问题描述 投票:0回答:1

我创建了一个带有标签的滑块。每一个标签必须包含一个相应的背景图片,但在我的例子中,图片必须在元素的背景中。但在我的例子中,图像必须在元素的背景中,当点击一个标签时,图像必须改变,是否可以这样做?

image example

        <header class="header">
            <div class="first_slider">
                <div class="tabsy">

                    <input type="radio" id="tab1" name="tab" checked>
                    <label class="tabButton" for="tab1"><span class="btn_content">école</span></label>
                    
                    <div class="tab">
                        <div class="content">
                            <img src="./app/img/slider_2.jpg" alt="">
                            <h3>Un printemps robotique à Arts et Métiers</h3>
                            <p>Le campus Arts et Métiers de Lille, se positionne comme un acteur incontournable de la robotique par ses activités de formation, de recherche et de transfert technologique. </p>
                            <a href=""> <i class="fas fa-angle-right"></i> Lire plus</a>
                        </div>
                    </div>
        
                    <input type="radio" id="tab2" name="tab">
                    <label class="tabButton" for="tab2"><span class="btn_content">Robotique</span> </label>
                    
                    <div class="tab">
                        <div class="content">
                            <h3>Heading 2</h3>
                            <p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
                            <a href=""><i class="fas fa-angle-right"></i> Lire plus</a>
                        </div>
                    </div>
        
                    <input type="radio" id="tab3" name="tab">
                    <label class="tabButton" for="tab3"><span class="btn_content">industrie du futur</span> </label>
                    
                    <div class="tab">
                        <div class="content">
                            <h3>Heading 3</h3>
                            <p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
                            <a href=""><i class="fas fa-angle-right"></i> Lire plus</a>
                        </div>
                    </div>
        
                </div>
            </div>
            <div class="second_slider">

            </div>
        </header>
css image tabs tags
1个回答
0
投票

我还在试图弄清楚你到底是什么意思,但我是这样理解的。

$('.tab').click(function() {
  switch($(this).attr('id'))
  {
  	case "tab1":
    	$('header').css('background-image', 'url(imagefile1)');
  	break;
    case "tab2":
    	$('header').css('background-image', 'url(imagefile2)');
  	break;
    case "tab3":
    	$('header').css('background-image', 'url(imagefile3)');
  	break;
  }
});
.tab{
  width:50px;
  height:20px;
  float:left;
  border:2px solid black;
  margin: 2px;
  padding:2px;
}

.header{
  width:500px;
  height:250px;
  border:1px solid black;
  background
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="tabContainer">
  <div class="tab" id="tab1"> TAB 1</div>
  <div class="tab" id="tab2"> TAB 2</div>
  <div class="tab" id="tab3"> TAB 3</div>
</div>

<header class="header">
  
</header>
© www.soinside.com 2019 - 2024. All rights reserved.