leeda-cloud
[HTML & CSS]background-attachment:fixed 모바일에서 작동하지 않을 때 해결법 본문
HTML & CSS & JS/HTML&CSS
[HTML & CSS]background-attachment:fixed 모바일에서 작동하지 않을 때 해결법
leeda-cloud 2023. 7. 13. 15:24background-attachment:fixed를 사용해 모바일에서 확인해 본 결과 모바일에서는 작동하지 않거나 버벅인다.
이를 잡기 위해서는 clip-path를 이용해야 한다.
clip-path는 클리핑 마스크로써 다양한 모양을 만들 수 있다.
하지만 브라우저 호환성은 한번 알아만 두자.
https://caniuse.com/?search=clip-path
"clip-path" | Can I use... Support tables for HTML5, CSS3, etc
CSS Masks Method of displaying part of an element, using a selected image as a mask
caniuse.com
html
<div class="bg-fixed">
<div class="bg-wrap">
<div class="bg"></div>
</div>
</div>
css
.bg-fixed {
position: relative;
width: 100%;
height: 300px;
}
.bg-wrap {
clip: rect(0, auto, auto, 0);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.bg {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-size: cover;
background-position: center center;
background-image: url("https://picsum.photos/200/300")
}
참고 url : https://css-tricks.com/fixed-background-effect/
The Search For a Fixed Background Effect With Inline Images | CSS-Tricks
I was working on a client project a few days ago and wanted to create a certain effect on an <img>. See, background images can do the effect I was
css-tricks.com
'HTML & CSS & JS > HTML&CSS' 카테고리의 다른 글
[CSS] flex 정리 (0) | 2023.12.01 |
---|---|
[CSS] svg에 animation 적용하기 (2) | 2023.07.13 |
[CSS] 모바일에서 링크 클릭시 잡히는 하이라이트 ( -webkit-tap-highlight-color) 수정하기 (0) | 2023.07.13 |
[HTML] 아이폰 모바일(safari)에서 비디오 자동 재생(autoplay)이 안 될 때 해결법 (1) | 2023.07.13 |
[SASS(SCSS)] 정리 (1) | 2023.07.13 |
Comments