简体   繁体   English

如何添加子div背景图片并将其应用于整个父部分

[英]how to add child div background image and applied to entire parent section

how to add child div background image and applied to entire parent section.Means i have section as parent class with child div. 如何添加子div的背景图像并应用于整个父节。意味着我有节作为子div的父类。

 .section-bg{ padding-top:35px; background: transparent url('../../assets/images/bg-page-img1.png') repeat scroll 0px 0px ; background-attachment: fixed; } 
  <section class="bet-section inner-section " style=""> <div class="section-bg"></div> <div class="row"> <div class="col-md-5 col-md-offset-1 image-right-pad"> <img src="./assets/images/img-content/th-1.jpg"> </div> <div class="col-md-6 content"> <h2><span style="display:block">Our</span> <span style="font-size: 54px; font-weight: bold; padding-top: 60px; color: rgb(96, 31, 76);">Story</span></h2> <br> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore </p> </div> </div> </section> 

$(document).ready(function(){
    $(".section-bg").parent().css("background-image",
          + $(".section-bg").css("background-image"));

});

i don't understand why you want this ? 我不明白你为什么要这个? you can write with CSS or inline CSS the background-image to the parent 您可以使用CSS或内联CSS将background-image写给parent

also , in your CSS you set the background-attachment:scroll and then you overwrite it in the next line with background-attachment:fixed . 同样,在CSS中,设置background-attachment:scroll ,然后在下一行中将它用background-attachment:fixed覆盖。 that's not correct. 那是不对的。 choose one :) 选一个 :)

my only guess is that you want to change the background-image of the parent depending on what background-image the child has. 我唯一的猜测是您要根据childbackground-image更改parent background-image so you could do something like this 所以你可以做这样的事情

see snippet : 见片段:

let me know if it helps . 让我知道是否有帮助。

 var bck = $(".section-bg").css("background-image") $(".bet-section").css("background-image", bck); 
 .section-bg{ padding-top:35px; background: transparent url('http://beerhold.it/579/300') no-repeat scroll 0px 0px ; } .bet-section { background-repeat:no-repeat; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section class="bet-section inner-section " style=""> <div class="section-bg"></div> <div class="row"> <div class="col-md-5 col-md-offset-1 image-right-pad"> <img src="./assets/images/img-content/th-1.jpg"> </div> <div class="col-md-6 content"> <h2><span style="display:block">Our</span> <span style="font-size: 54px; font-weight: bold; padding-top: 60px; color: rgb(96, 31, 76);">Story</span></h2> <br> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore </p> </div> </div> </section> 

or without JQ you could simply do this . 没有JQ,您可以简单地做到这一点。 this would be the logical way to do it. 这将是合乎逻辑的方式。

 .bet-section { background: transparent url('http://beerhold.it/579/300') no-repeat scroll 0px 0px ;} .section-bg{ padding-top:35px; } 
 <section class="bet-section inner-section " style=""> <div class="section-bg"></div> <div class="row"> <div class="col-md-5 col-md-offset-1 image-right-pad"> <img src="./assets/images/img-content/th-1.jpg"> </div> <div class="col-md-6 content"> <h2><span style="display:block">Our</span> <span style="font-size: 54px; font-weight: bold; padding-top: 60px; color: rgb(96, 31, 76);">Story</span></h2> <br> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore </p> </div> </div> </section> 

or you could just write inline like this : 或者您可以像这样编写内联:

<section class="bet-section inner-section " style="background-image:url('image url')">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在父div中使用Jquery而不影响子div的情况下淡入和淡出背景图像? - How can I fade are background image in and out using Jquery in a parent div without having it affect the child div? 如何将一个类添加到div的父级子级 - how to add a class to parent child of a div 如何使整个背景图像可以点击div? - How can i make the div clickable with entire background image? 将鼠标悬停在javascript或jquery中的子div上,无法更改父div的背景图片 - Trouble changing background image of parent div by hovering over child div in javascript or jquery 悬停父级时如何向子级 div 添加样式? - How can I add a style to a child div when hovering the parent? 如何将父Div的背景图像覆盖其子 - How to Overlap a Parent Div's Background Image Over its Children HTML5:将图片添加到父div并保持子div图片可见 - Html5: add image to a parent div and keep the child div images visible 显示子部分时在父div上进行过渡扩展 - Expanding with transition on parent div when displaying child section 如果背景图片等于特定图片,如何向div添加类 - How to add class to div if background image equals a particular image 当子容器div处于活动状态时,如何禁用父背景div? - How can I disable parent background div when a child container div is active?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM