CSS

[background] CSS - background-attachment 속성 - 배경이미지 고정 (= background-attachment속성 = 백그라운드어태치먼트속성) ★

목차

  1. background-attachment 예제 - 배경이미지 고정 O
  2. background-attachment 정의
  3. background-attachment 구문
  4. background-attachment 예제 - 배경이미지 고정 X
  5. background-attachment 이슈 - 고정 배경이미지 좌우 흔들림 방지

 

background-attachment 예제 - 배경이미지 고정 O

 

<style>
body {
     background-image: url("http://i.imgur.com/MzHQIAK.jpg");
     background-repeat: no-repeat;
     background-attachment : fixed;
}
div {
     height:2000px;
}
h1  {
     color:white;
}
</style>

<body> 
    <div><h1>홈짱닷컴 (homzzang.com)</h1></div>
</body>

 

결과보기

 

background-attachment 정의


배경이미지 고정시킬건지, 스크롤과 함께 움직이게 할건지 지정.

 


 

1.

  • 기본값 : scroll
  • 상속여부 : X
  • 애니효과 : X
  • CSS버전 : CSS1
  • JS구문 : object.style.backgroundAttachment="fixed";

 

2.

사파리 제외한 주요 최신 브라우저 모두 지원.

 

3. MDN background-attachment 예제보기

https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment

 


background-attachment 구문

 
selector {background-attachment: scroll|fixed|local|initial|inherit;}

 


[속성값]

 

scroll  
배경이미지가 페이지와 함께 스크롤 O. (기본값)
  • 배경이미지가 해당 요소 자체 기준으로 고정됨. 
  • 이미지가 요소의 테두리에 효과적으로 부착됨.
 
fixed   
배경이미지가 페이지와 함께 스크롤 X. (= 배경이미지 고정.)
  • 배경이미지가 뷰포트 기준으로 고정됨.
  • background-clip: text와 호환 X
 
local
배경이미지가 요소 내용과 함께 스크롤.
 
initial
이 속성의 기본값으로 설정.
            
inherit  
부모요소의 속성값 상속.

 

background-attachment 예제 - 배경이미지 고정 X

 

<style>
body {
     background-image: url("http://i.imgur.com/MzHQIAK.jpg");
     background-repeat: no-repeat;
     background-attachment : scroll;
}
div {
     height:2000px;
}
h1  {
     color:white;
}
</style>
<body> 
    <div><h1>홈짱닷컴 (homzzang.com)</h1></div>
 

background-attachment 이슈 - 고정 배경이미지 좌우 흔들림 방지

[원인]

 

세로 스크롤바 존재 여부.

 


[해결]

 

body 스타일에 아래 코드 추가해 항상 세로 스크롤바가 존재하게 만듦.
body {min-height:1000px;}

 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
intro CSS - inherit (인헤리트) - 상속개념 ★
background CSS - background 속성 ★ - 배경 일괄 (= background속성 = 백그라운드속성)
background CSS - background-color 속성 ★ - 배경색깔(=배경색상=배경컬러 = background-c…
background CSS - background-image 속성 ★ - 배경이미지 (= background-image속성 = …
background CSS - background-repeat 속성 ★ - 배경이미지 반복 (= 배경반복 = background…
background CSS - background-attachment 속성 - 배경이미지 고정 (= background-atta…
background CSS - background-position 속성 = 배경위치 (= background-position속성…
border CSS - border 속성 ★ - 테두리일괄 (= border속성 = 보더속성) (상속X)
border CSS - border-style 속성 ★ - 테두리모양일괄 (= border-style속성 = 보더스타일속…
border CSS - border-width 속성 - 테두리두께일괄 (= 테두리너비일괄 = border-width속성 …
border CSS - border-color 속성 - 테두리색상일괄 (= 테두리색깔일괄 = border-color속성 …
border CSS - border-top 속성 - 테두리상단일괄 (= border-top속성 = 보더탑속성 / 보더톱속…
border CSS - border-right 속성 - 테두리우측일괄 (= 테두리오른쪽일괄 = border-right속성…
border CSS - border-bottom 속성 - 테두리하단일괄 (= border-bottom속성 = 보더바텀속성…
border CSS - border-left 속성 - 테두리좌측일괄 (= 테두리왼쪽일괄 = border-left속성 = …
3/33
목록
  • 채팅방
  • 필독
1. 채팅창 헤드에서 접속자 확인 2. 닉네임 클릭해 1:1 채팅 가능 3. 닉네임 클릭해 귓속말 가능 4. 닉네임 클릭해 호출하기 가능 5. 우하단 클릭해 환경 설정 가능 6. 의뢰글 작성 후 의뢰 상담 가능 7. 질문글 작성 후 질문 상담 가능 8. 채팅방에 개인정보 입력 금지 9. 채팅방에 광고 욕설 비방 금지
 홈  PC버전 로그인 일본어
웹디자인언어
서버관리언어
고급코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 2
웹유틸
회원센터
홈짱 PC버전 로그인