1. 개발자를 위한 웹 기술
  2. CSS
  3. CSS 참고서
  4. Properties
  5. place-items

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

place-items

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2020년 1월⁩.

* Some parts of this feature may have varying levels of support.

CSSplace-items 단축 속성그리드 혹은 플렉스박스 같은 관계형 레이아웃 시스템에서 블록 방향과 인라인 방향에서 (예를 들어, align-itemsjustify-items 속성) 한번에 요소들을 정렬합니다. 만일 두번째 값이 지정되지 않는다면, 첫번째 값이 두번째 값으로도 사용됩니다.

시도해 보기

place-items: center stretch;
place-items: center start;
place-items: start end;
place-items: end center;
<section class="default-example" id="default-example">
 <div class="example-container">
 <div class="transition-all" id="example-element">
 <div>One</div>
 <div>Two</div>
 <div>Three</div>
 </div>
 </div>
</section>
#example-element {
 border: 1px solid #c5c5c5;
 display: grid;
 grid-template-columns: 1fr 1fr;
 grid-auto-rows: 80px;
 grid-gap: 10px;
 width: 220px;
}
#example-element > div {
 background-color: rgba(0, 0, 255, 0.2);
 border: 3px solid blue;
}

구성 속성

이 속성은 다음 CSS의 단축형입니다.

구문

css
/* 위치 정렬 */
place-items: center;
place-items: normal start;
place-items: center normal;
place-items: start legacy;
place-items: end normal;
place-items: self-start legacy;
place-items: self-end normal;
place-items: flex-start legacy;
place-items: flex-end normal;
/* 기준선 정렬 */
place-items: baseline normal;
place-items: first baseline legacy;
place-items: last baseline normal;
place-items: stretch legacy;
/* 전역 값 */
place-items: inherit;
place-items: initial;
place-items: revert;
place-items: revert-layer;
place-items: unset;

아래 형태 중 하나의 값을 취합니다.

  • 블록 방향과 인라인 방향 모두를 설정하기 위한 정렬 단일 align-items 값.
  • 블록 방향의 정렬을 설정하기 위한 align-items 값, 인라인 방향의 정렬을 설정하기 위한 justify-items 값.

형식 정의

초기값 as each of the properties of the shorthand:
적용대상all elements
상속 no
계산 값 as each of the properties of the shorthand:
Animation type discrete

형식 구문

place-items = 
<'align-items'> <'justify-items'> ?

<align-items> =
normal |
stretch |
<baseline-position> |
<overflow-position>? <self-position> |
anchor-center

<justify-items> =
normal |
stretch |
<baseline-position> |
<overflow-position>? [ <self-position> | left | right ] |
legacy |
legacy && [ left | right | center ] |
anchor-center

<baseline-position> =
[ first | last ] ? &&
baseline

<overflow-position> =
unsafe |
safe

<self-position> =
center |
start |
end |
self-start |
self-end |
flex-start |
flex-end

예제

플렉스 컨테이너에 요소 배치하기

플렉스박스에서는 주축 요소가 하나의 그룹으로 취급되기 때문에 justify-self 혹은 justify-items 가 적용되지 않습니다. 따라서 두번째 값은 무시됩니다.

div > div {
 box-sizing: border-box;
 border: 2px solid #8c8c8c;
 width: 50px;
 display: flex;
 align-items: center;
 justify-content: center;
}
#item1 {
 background-color: #8cffa0;
 min-height: 30px;
 font-size: 2em;
}
#item2 {
 background-color: #a0c8ff;
 min-height: 50px;
}
#item3 {
 background-color: #ffa08c;
 min-height: 40px;
}
#item4 {
 background-color: #ffff8c;
 min-height: 60px;
}
#item5 {
 background-color: #ff8cff;
 min-height: 70px;
}
#item6 {
 background-color: #8cffff;
 min-height: 50px;
}
select {
 font-size: 16px;
}
.row {
 margin-top: 10px;
}
<div id="container">
 <div id="item1">1</div>
 <div id="item2">2</div>
 <div id="item3">3</div>
</div>
<div class="row">
 <label for="values">place-items: </label>
 <select id="values">
 <option value="stretch">stretch</option>
 <option value="start">start</option>
 <option value="center">center</option>
 <option value="end">end</option>
 <option value="left">left</option>
 <option value="right">right</option>
 <option value="auto center">auto center</option>
 <option value="normal start">normal start</option>
 <option value="center normal">center normal</option>
 <option value="start auto">start auto</option>
 <option value="end normal">end normal</option>
 <option value="self-start auto">self-start auto</option>
 <option value="self-end normal">self-end normal</option>
 <option value="flex-start auto">flex-start auto</option>
 <option value="flex-end normal">flex-end normal</option>
 <option value="left auto">left auto</option>
 <option value="right normal">right normal</option>
 <option value="baseline normal">baseline normal</option>
 <option value="first baseline auto">first baseline auto</option>
 <option value="last baseline normal">last baseline normal</option>
 <option value="stretch auto">stretch auto</option>
 </select>
</div>
const values = document.getElementById("values");
const container = document.getElementById("container");
values.addEventListener("change", (evt) => {
 container.style.placeItems = evt.target.value;
});

CSS

css
#container {
 height: 200px;
 width: 240px;
 place-items: stretch; /* 리스트에 있는 다른 옵션을 선택하여 값을 변경할 수 있습니다. */
 background-color: #8c8c8c;
 display: flex;
}

결과

그리드 컨테이너에 요소 배치하기

다음 그리드 컨테이너는 요소들이 배치된 그리드 영역보다 작기 때문에 place-items 는 요소들을 블록과 인라인 차원에서 요소들을 이동시킵니다.

div > div {
 box-sizing: border-box;
 border: 2px solid #8c8c8c;
}
#item1 {
 background-color: #8cffa0;
 min-height: 30px;
 font-size: 2em;
}
#item2 {
 background-color: #a0c8ff;
 min-height: 50px;
}
#item3 {
 background-color: #ffa08c;
 min-height: 40px;
}
#item4 {
 background-color: #ffff8c;
 min-height: 60px;
}
#item5 {
 background-color: #ff8cff;
 min-height: 70px;
}
#item6 {
 background-color: #8cffff;
 min-height: 50px;
}
select {
 font-size: 16px;
}
.row {
 margin-top: 10px;
}
<div id="gridcontainer">
 <div id="item1">1</div>
 <div id="item2">2</div>
 <div id="item3">3</div>
 <div id="item4">4</div>
 <div id="item5">5</div>
</div>
<div class="row">
 <label for="gridvalues">place-items: </label>
 <select id="gridvalues">
 <option value="stretch">stretch</option>
 <option value="start">start</option>
 <option value="center">center</option>
 <option value="end">end</option>
 <option value="left">left</option>
 <option value="right">right</option>
 <option value="auto center">auto center</option>
 <option value="normal start">normal start</option>
 <option value="center normal">center normal</option>
 <option value="start auto">start auto</option>
 <option value="end normal">end normal</option>
 <option value="self-start auto">self-start auto</option>
 <option value="self-end normal">self-end normal</option>
 <option value="flex-start auto">flex-start auto</option>
 <option value="flex-end normal">flex-end normal</option>
 <option value="left auto">left auto</option>
 <option value="right normal">right normal</option>
 <option value="baseline normal">baseline normal</option>
 <option value="first baseline auto">first baseline auto</option>
 <option value="last baseline normal">last baseline normal</option>
 <option value="stretch auto">stretch auto</option>
 </select>
</div>
const values = document.getElementById("gridvalues");
const container = document.getElementById("gridcontainer");
values.addEventListener("change", (evt) => {
 container.style.placeItems = evt.target.value;
});

CSS

css
#gridcontainer {
 height: 200px;
 width: 240px;
 place-items: stretch; /* 리스트에 있는 다른 옵션을 선택하여 값을 변경할 수 있습니다. */
 background-color: #8c8c8c;
 display: grid;
 grid-template-columns: repeat(3, 1fr);
}
#gridcontainer > div {
 width: 50px;
}

결과

명세서

Specification
CSS Box Alignment Module Level 3
# place-items-property

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /