다음 HTML에서 중간 div의 높이를 200px로 수동 설정했습니다. div의 높이가 브라우저에서 보이는 영역의 높이와 같도록이 높이를 자동으로 조정하려면 어떻게해야합니까? 순수한 CSS로이 작업을 수행 할 수 있습니까, 아니면 JavaScript가 필요합니까?보이는 영역을 기준으로 div의 높이를 설정하십시오.
<p>Scroll Up and Down this page to see the parallax scrolling effect.</p>
<div class="parallax"></div>
<div class="red">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
그리고 CSS :
.parallax {
/* The image used */
background-image: url("http://az-themes.bluxart.netdna-cdn.com/ibuki/wp-content/uploads/2014/06/blog-img.jpg");
/* Set a specific height */
height: 200px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.red {
height:1000px;
background-color:red;
color:white;
font-size: 40px;
}
Wokring 예 here를 찾을 수 있습니다.
사용 100vh은 CSS에서의 높이와 (VH 부 뷰포트 높이). 100은 뷰포트 높이의 100 &라고 말합니다. 당신은 또한 너비에 대한 vw 있습니다. – creativekinetix
'vh'에 대한 브라우저 지원 : http://caniuse.com/#feat=viewport-units – Sebastian
꽤 광범위하게 지원됩니다. IE에서도 vmax 유닛 만 잃어 버리고 있습니다. 인쇄 및 3D 변환 등과 관련된 다른 버그가 있지만 여기에는 많은 문제가 있다고 생각하지 않습니다. – creativekinetix