display
display
CSS 속성은 요소를
블록과 인라인 요소 중 어느 쪽으로 처리할지와 함께,
플로우, 그리드,
플렉스처럼 자식 요소를 배치할 때 사용할 레이아웃을 설정합니다.
display
속성은, 형식적으로는 요소의 내부와 외부 디스플레이 유형을 설정합니다. 외부 디스플레이 유형은
플로우 레이아웃에 요소가 참여하는 방법을 나타내고, 내부 디스플레이 유형은 자식의 레이아웃 방식을 설정합니다.
display
의 일부 값은 자신만의 명세를 가지고 있습니다. 이 문서의 끝에서 찾을 수 있는 명세표를 참고하세요.
구문
display
속성은 키워드 값을 사용해 지정합니다. 키워드는 6개의 카테고리로 분류할 수 있습니다.
.container { display: <display-keyword>; }
바깥쪽
<display-outside>
(en-US)- : 요소의 외부 디스플레이 유형을 설정하는 키워드입니다. 외부 디스플레이 유형은 플로우 레이아웃에서 요소 자신의 역할과 마찬가지입니다.
block
- : The element generates a block element box, generating line breaks both before and after the element when in the normal flow.
inline
- : The element generates one or more inline element boxes that do not generate line breaks before or after themselves. In normal flow, the next element will be on the same line if there is space
참고: Browsers that support the two-value syntax, on finding the outer value only, such as when
display: block
or display: inline
is specified, will set the inner value to
flow
. This will result in expected behavior; for example, if you specify an element to be block, you
would expect that the children of that element would participate in block and inline normal flow layout.
안쪽
<display-inside>
(en-US)-
요소의 내부 디스플레이 유형을 설정하는 키워드입니다. 내부 디스플레이 유형은 대체 요소가 아닌 요소의 콘텐츠 서식과 배치 방법을 나타냅니다.
flow
Experimental-
The element lays out its contents using flow layout (block-and-inline layout).
If its outer display type is
inline
orrun-in
, and it is participating in a block or inline formatting context, then it generates an inline box. Otherwise it generates a block container box.Depending on the value of other properties (such as
position
,float
, oroverflow
) and whether it is itself participating in a block or inline formatting context, it either establishes a new block formatting context (BFC) for its contents or integrates its contents into its parent formatting context. flow-root
-
The element generates a block element box that establishes a new block formatting context, defining where the formatting root lies.
table
-
These elements behave like HTML
<table>
elements. It defines a block-level box. flex
-
The element behaves like a block element and lays out its content according to the flexbox model.
grid
-
The element behaves like a block element and lays out its content according to the grid model.
ruby
Experimental-
The element behaves like an inline element and lays out its content according to the ruby formatting model. It behaves like the corresponding HTML
<ruby>
elements.
참고: Browsers that support the two-value syntax, on finding the inner value only, such as when
display: flex
or display: grid
is specified, will set their outer value to
block
. This will result in expected behavior; for example, if you specify an element to be
display: grid
, you would expect that the box created on the grid container would be a block-level box.
리스트 아이템
<display-listitem>
(en-US)-
요소가 콘텐츠 블록 박스를 생성하고, 리스트 아이템 인라인 박스를 분리합니다.
A single value of list-item
will cause the element to behave like a list item. This can be used together
with list-style-type
(en-US) and list-style-position
(en-US).
list-item
can also be combined with any <display-outside>
(en-US) keyword and the
flow
or flow-root
<display-inside>
(en-US) keywords.
참고: In browsers that support the two-value syntax, if no inner value is specified, it will
default to flow
. If no outer value is specified, the principal box will have an outer display type of
block
.
내부적
<display-internal>
-
table
,ruby
등 일부 레이아웃 모델은 복잡한 내부 구조를 가지며, 자식과 자손이 채워넣을 여러가지 역할을 지닙니다. 이 항목은 그런 특정 레이아웃 모드에서만 의미를 갖는 "내부적"인 값을 정의합니다.table-row-group
-
These elements behave like
<tbody>
HTML elements. table-header-group
-
These elements behave like
<thead>
HTML elements. -
These elements behave like
<tfoot>
HTML elements. table-row
-
These elements behave like
<tr>
HTML elements. table-cell
-
These elements behave like
<td>
HTML elements. table-column-group
-
These elements behave like
<colgroup>
HTML elements. table-column
-
These elements behave like
<col>
HTML elements. table-caption
-
These elements behave like
<caption>
HTML elements. ruby-base
Experimental-
These elements behave like
<rb>
HTML elements. ruby-text
Experimental-
These elements behave like
<rt>
HTML elements. ruby-base-container
Experimental-
These elements behave like
<rbc>
HTML elements generated as anonymous boxes. ruby-text-container
Experimental-
These elements behave like
<rtc>
HTML elements.
박스
<display-box>
(en-US)-
요소의 디스플레이 박스를 생성해야 하는지 지정합니다.
contents
-
These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that the CSS Display Level 3 spec defines how the
contents
value should affect "unusual elements" — elements that aren't rendered purely by CSS box concepts such as replaced elements. See Appendix B: Effects of display: contents on Unusual Elements for more details.Due to a bug in browsers, this will currently remove the element from the accessibility tree — screen readers will not look at what's inside. See the Accessibility concerns section below for more details.
none
-
레이아웃에 영향을 주지 않도록 요소의 display를 끄게 합니다(웹문서는 마치 해당 요소가 존재하지 않는 것처럼 렌더링되어집니다). 모든 하위 요소들 또한 display를 끄게 합니다. 요소가 정상적으로 본연의 공간을 가지고 있게 하면서 해당 공간에 아무것도 렌더링되지 않게 하려면,
visibility
속성으로 대체하여 사용하시기 바랍니다.
레거시
<display-legacy>
(en-US)-
CSS 2는
display
속성에 단일 키워드만 사용했으므로, 같은 레이아웃 모드를 위해 블록 레벨과 인라인 레벨 키워드를 각각 필요로 했습니다.inline-block
-
The element generates a block element box that will be flowed with surrounding content as if it were a single inline box (behaving much like a replaced element would).
It is equivalent to
inline flow-root
. inline-table
-
The
inline-table
value does not have a direct mapping in HTML. It behaves like an HTML<table>
element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context.It is equivalent to
inline table
. inline-flex
-
The element behaves like an inline element and lays out its content according to the flexbox model.
It is equivalent to
inline flex
. inline-grid
-
The element behaves like an inline element and lays out its content according to the grid model.
It is equivalent to
inline grid
.
Which syntax should you use now?
The Level 3 specification details two values for the display
property — enabling the specification of the
outer and inner display type explicitly — but this is not yet well-supported by browsers.
The <display-legacy>
methods allow the same results with single keyword values, and should be
favoured by developers until the two keyword values are better supported. For example, using two values you might
specify an inline flex container as follows:
.container {
display: inline flex;
}
This can currently be specified using a single value.
.container {
display: inline-flex;
}
For more information on these changes to the specification, see the article Adapting to the new two-value syntax of display (en-US).
Global
/* Global values */
display: inherit;
display: initial;
display: unset;
안내서 및 예제
The individual pages for the different types of value that display
can have set on it feature multiple
examples of those values in action — see the Syntax section. In addition, see the following material,
which covers the various values of display in depth.
CSS Flow Layout (display: block
, display: inline
)
display: flex
- Basic concepts of flexbox
- Aligning Items in a Flex Container
- Controlling Ratios of Flex Items Along the Main Axis (en-US)
- Cross-browser Flexbox mixins (en-US)
- Mastering Wrapping of Flex Items (en-US)
- Ordering Flex Items (en-US)
- Relationship of flexbox to other layout methods (en-US)
- Backwards Compatibility of Flexbox (en-US)
- Typical use cases of Flexbox
display: grid
- Basic Concepts of Grid Layout
- Relationship to other layout methods
- Line-based placement
- Grid template areas
- Layout using named grid lines
- Auto-placement in grid layout (en-US)
- Box alignment in grid layout (en-US)
- Grids, logical values and writing modes (en-US)
- CSS Grid Layout and Accessibility (en-US)
- CSS Grid Layout and Progressive Enhancement (en-US)
- Realizing common layouts using grids (en-US)
접근성 고려사항
display: none
Using a display
value of none
on an element will remove it from the
accessibility tree. This will
cause the element and all its descendant elements to no longer be announced by screen reading technology.
If you want to visually hide the element, a more accessible alternative is to use a combination of properties to remove it visually from the screen but keep it parseable by assistive technology such as screen readers.
display: contents
Current implementations in most browsers will remove from the
accessibility tree any element
with a display
value of contents
(but descendants will remain). This will cause the element
itself to no longer be announced by screen reading technology. This is incorrect behavior according to the
CSS specification.
Tables
Changing the display
value of a <table>
element to block
,
grid
, or flex
will alter its representation in the
accessibility tree. This will
cause the table to no longer be announced properly by screen reading technology.
명세
Specification |
---|
CSS Display Module Level 3 # the-display-properties |
브라우저 호환성
BCD tables only load in the browser