2016-08-11 8 views
0

자식 div 배경 이미지를 추가하고 전체 부모 섹션에 적용하는 방법. 즉, 하위 div가있는 부모 클래스로 섹션이 있습니다.자식 div 배경 이미지를 추가하고 전체 부모 섹션에 적용하는 방법

.section-bg{ 
 
padding-top:35px; 
 
background: transparent url('../../assets/images/bg-page-img1.png') repeat scroll 0px 0px ; 
 
background-attachment: fixed; 
 
}
\t <section class="bet-section inner-section " style=""> 
 
\t <div class="section-bg"></div> 
 
\t <div class="row"> 
 
\t <div class="col-md-5 col-md-offset-1 image-right-pad"> 
 
\t <img src="./assets/images/img-content/th-1.jpg"> 
 
\t 
 
\t </div> 
 
\t <div class="col-md-6 content"> 
 
\t 
 
\t <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> 
 
\t </div> 
 
\t </div> 
 
\t 
 
\t </section>

+0

왜 당신이 아이를 어떻게해야합니까? 왜 부모님 께 맡길 수 없습니까? –

+0

비록 내가 왜 CSS 또는 인라인 CSS에서 배경 이미지를 추가하는 대신 jQuery를 통해이 작업을 수행해야하는지 이해할 수는 없지만 아래 답변을 제공했습니다. 도움이되는지 알려주세요. –

답변

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

}); 
+0

스택 오버플로에 오신 것을 환영합니다! 이 코드 스 니펫이 질문을 해결할 수 있지만 [설명 포함] (// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) 정말 게시물의 품질을 향상시키는 데 도움이됩니다. 앞으로 독자의 질문에 답하고 있으며 코드 제안의 이유를 알지 못할 수도 있습니다. 또한 코드와 설명의 가독성을 떨어 뜨리기 때문에 주석을 설명하는 코드를 사용하지 마십시오! – FrankerZ

0

당신이 원하는 내가 왜 이해가 안 돼요? 당신은 parent

background-image도, 당신의 CSS에 당신이 background-attachment:scroll을 설정 한 다음 background-attachment:fixed와 함께 다음 줄에 덮어 CSS 또는 인라인 CSS로 쓸 수 있습니다. 그건 맞지 않아. 하나를 선택 :

내 유일한 생각 엔 당신이 background-imagechild이 무슨에 따라 parentbackground-image을 변경하려는 것입니다.

이 도움이된다면 알려 : 그래서 당신은

이 조각을 볼 같은 것을 할 수 있습니다. JQ없이

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=""> 
 
\t <div class="section-bg"></div> 
 
\t <div class="row"> 
 
\t <div class="col-md-5 col-md-offset-1 image-right-pad"> 
 
\t <img src="./assets/images/img-content/th-1.jpg"> 
 
\t 
 
\t </div> 
 
\t <div class="col-md-6 content"> 
 
\t 
 
\t <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> 
 
\t </div> 
 
\t </div> 
 
\t 
 
\t </section>

또는

는 이렇게 간단하게 할 수있다. 이것은 그것을하는 논리적 인 방법 일 것입니다.

.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=""> 
 
\t <div class="section-bg"></div> 
 
\t <div class="row"> 
 
\t <div class="col-md-5 col-md-offset-1 image-right-pad"> 
 
\t <img src="./assets/images/img-content/th-1.jpg"> 
 
\t 
 
\t </div> 
 
\t <div class="col-md-6 content"> 
 
\t 
 
\t <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> 
 
\t </div> 
 
\t </div> 
 
\t 
 
\t </section>

또는 당신은 다음과 같이 인라인 작성할 수

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

관련 문제