【问题标题】:image background in another container另一个容器中的图像背景
【发布时间】:2020-05-04 11:14:33
【问题描述】:

我创建了一个带有标签的滑块。每个选项卡必须包含相应的背景图像。但在我的情况下,图像必须在元素的背景中。 单击选项卡时,图像必须更改 可以这样做吗?

        <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 设置元素背景
  • 我明白,但我希望我的图像适合我的标题标签而不是我的标签容器!我已经更新了我的图片示例

标签: css image tabs tags


【解决方案1】:

我仍在试图弄清楚你的意思。 但这就是我的解释。

$('.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>

【讨论】:

  • 我在 CSS 中动画标签幻灯片
猜你喜欢
  • 1970-01-01
  • 2013-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-14
  • 2018-04-23
  • 2012-10-07
  • 1970-01-01
相关资源
最近更新 更多