[英]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. 我唯一的猜测是您要根据child
的background-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.