CSS / Reference / background-attachment

개요

background-attachment는 배경 이미지의 스크롤 여부를 정하는 속성입니다.

  • 기본값 : scroll
  • 상속 : No
  • 애니메이션 : No
  • 버전 : CSS Level 1

문법

background-attachment: scroll | fixed | local | initial | inherit
  • scroll : 선택한 요소와 같이 움직입니다. 내용을 스크롤하면 배경 이미지는 스크롤되지 않습니다.
  • fixed : 움직이지 않습니다.
  • local : 선택한 요소와 같이 움직입니다. 내용을 스크롤하면 배경 이미지도 스크롤됩니다.
  • initial : 기본값으로 설정합니다.
  • inherit : 부모 요소의 속성값을 상속받습니다.

예제

<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>CSS</title>
    <style>
      body {
        height: 600px;
      }
      div {
        width: 30%;
        height: 300px;
        overflow: auto;
        float: left;
        margin: 0px 10px;
        background-image: url( "images/bg-300x200.jpg" );
        background-repeat: no-repeat;
        border: 1px solid #bcbcbc;
        font-size: 36px;
      }
      .jb-scroll {
        background-attachment: scroll;
      }
      .jb-fixed {
        background-attachment: fixed;
      }
      .jb-local {
        background-attachment: local;
      }
    </style>
  </head>
  <body>
    <div class="jb-scroll">
      <p>scroll</p>
      <ul>
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
        <li>Four</li>
        <li>Five</li>
        <li>Six</li>
        <li>Seven</li>
        <li>Eight</li>
        <li>Nine</li>
        <li>Ten</li>
      </ul>
    </div>
    <div class="jb-fixed">
      <p>fixed</p>
      <ul>
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
        <li>Four</li>
        <li>Five</li>
        <li>Six</li>
        <li>Seven</li>
        <li>Eight</li>
        <li>Nine</li>
        <li>Ten</li>
      </ul>
    </div>
    <div class="jb-local">
      <p>local</p>
      <ul>
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
        <li>Four</li>
        <li>Five</li>
        <li>Six</li>
        <li>Seven</li>
        <li>Eight</li>
        <li>Nine</li>
        <li>Ten</li>
      </ul>
    </div>
  </body>
</html>

  • 속성값을 fixed로 하면 웹브라우저 가시 영역의 왼쪽 위를 기준으로 배경 이미지가 고정됩니다.
body {
  height: 600px;
  background-image: url( "images/bg-300x200.jpg" );
  background-repeat: no-repeat;
}
  • 위와 같이 수정하면 어디에 위치하는지 확인할 수 있습니다.

바깥쪽 스크롤바를 움직이면...

  • scroll : 선택한 요소와 같이 스크롤됩니다.
  • fixed : 움직이지 않습니다.
  • local : 선택한 요소와 같이 스크롤됩니다.

각 요소의 스크롤바를 움직이면...

  • scroll : 움직이지 않습니다.
  • fixed : 움직이지 않습니다.
  • local : 선택한 요소와 같이 스크롤됩니다.

같은 카테고리의 다른 글
CSS / Reference / border-style

CSS / Reference / border-style

border-style은 테두리(border)의 모양을 정하는 속성으로, 다음 속성의 단축 속성입니다. border-top-style border-right-style border-bottom-style border-left-style

CSS / Reference / accent-color

CSS / Reference / accent-color

accent-color는 HTML의 폼 요소에 사용되는 강조 색상을 정하는 속성입니다. 기본적으로 브라우저는 사용자 인터페이스 요소에 특정한 시스템 색상을 사용하지만, accent-color를 사용하면 이러한 요소들의 강조 색상을 커스터마이즈할 수 있습니다.

CSS / Reference / backface-visibility

CSS / Reference / backface-visibility

backface-visibility는 요소의 뒷쪽에서 앞면이 보이게 할지 정하는 속성입니다. 기본값 : visible 상속 : No 애니메이션 : No 버전 : CSS Level 3

CSS / Reference / caption-side

CSS / Reference / caption-side

caption-side는 표(table)의 caption 위치를 정하는 속성입니다. 기본값 : top 상속 : Yes 애니메이션 : No 버전 : CSS Level 2

CSS / Reference / word-wrap

CSS / Reference / word-wrap

word-wrap은 띄어쓰기가 없는 긴 단어를 어떻게 처리할지 정하는 속성입니다. 기본값 : normal 상속 : Yes 애니메이션 : No 버전 : CSS Level 3

CSS / Reference / font-variant

CSS / Reference / font-variant

font-variant는 소문자를 작은 대문자, 즉 소문자 크기의 대문자로 바꾸는 속성입니다. 따라서 한글에서는 의미 없는 속성입니다. 기본값 : normal 상속 : Yes 애니메이션 : No 버전 : CSS Level 1

CSS / Reference / border-width

CSS / Reference / border-width

border-width은 테두리(border)의 두께를 정하는 속성으로, 다음 속성의 단축 속성입니다. border-top-width border-right-width border-bottom-width border-left-width

CSS / Reference / opacity

CSS / Reference / opacity

opacity로 요소의 투명도를 정할 수 있습니다. 기본값 : 1 상속 : No 애니메이션 : Yes 버전 : CSS Level 3

CSS / Reference / text-indent

CSS / Reference / text-indent

들여쓰기와 내어쓰기는 text-indent 속성으로 만듭니다. 값이 양수이면 들여쓰기, 값이 음수이면 내어쓰기가 됩니다. 내어쓰기를 할 때는 왼쪽에 여백을 적절히 줍니다.

CSS / Reference / font-style

CSS / Reference / font-style

font-style은 글자 모양을 정하는 속성으로, 기울임 여부를 정합니다. 기본값 : normal 상속 : Yes 애니메이션 : No 버전 : CSS Level 1