표시
표시 (Display)
표시(display) 유틸리티로 display, overflow, visibility 등을 빠르고 반응형으로 토글할 수 있어요.
출처: 문서
본문
예시
인라인 (Inline)
<Box component="div" sx={{ display: 'inline' }}>inline</Box>
<Box component="div" sx={{ display: 'inline' }}>inline</Box>
블록 (Block)
<Box component="span" sx={{ display: 'block' }}>block</Box>
<Box component="span" sx={{ display: 'block' }}>block</Box>
요소 숨기기
모바일 친화적인 개발을 더 빠르게 하려면, 반응형 display 클래스를 써서 기기별로 요소를 보이거나 숨기면 좋아요. 사이트의 완전히 다른 버전을 만들지 말고, 화면 크기에 따라 요소를 반응형으로 숨기는 방식을 권해요.
| Screen Size | Class |
|---|---|
| Hidden on all | sx={{ display: 'none' }} |
| Hidden only on xs | sx={{ display: { xs: 'none', sm: 'block' } }} |
| Hidden only on sm | sx={{ display: { xs: 'block', sm: 'none', md: 'block' } }} |
| Hidden only on md | sx={{ display: { xs: 'block', md: 'none', lg: 'block' } }} |
| Hidden only on lg | sx={{ display: { xs: 'block', lg: 'none', xl: 'block' } }} |
| Hidden only on xl | sx={{ display: { xs: 'block', xl: 'none' } }} |
| Visible only on xs | sx={{ display: { xs: 'block', sm: 'none' } }} |
| Visible only on sm | sx={{ display: { xs: 'none', sm: 'block', md: 'none' } }} |
| Visible only on md | sx={{ display: { xs: 'none', md: 'block', lg: 'none' } }} |
| Visible only on lg | sx={{ display: { xs: 'none', lg: 'block', xl: 'none' } }} |
| Visible only on xl | sx={{ display: { xs: 'none', xl: 'block' } }} |
<Box sx={{ display: { xs: 'block', md: 'none' }}}>
hide on screens wider than md
</Box>
<Box sx={{ display: { xs: 'none', md: 'block' }}}>
hide on screens smaller than md
</Box>
인쇄 시 표시 (Display in print)
<Box sx={{ display: 'block', displayPrint: 'none' }}>
Screen Only (Hide on print only)
</Box>
<Box sx={{ display: 'none', displayPrint: 'block' }}>
Print Only (Hide on screen only)
</Box>
Overflow
<Box component="div" sx={{ overflow: 'hidden' }}>
Not scrollable, overflow is hidden
</Box>
<Box component="div" sx={{ overflow: 'auto' }}>
Try scrolling this overflow auto box
</Box>
텍스트 넘침 (Text overflow)
<Box component="div" sx={{ textOverflow: 'clip' }}>
Lorem Ipsum is simply dummy text
</Box>
<Box component="div" sx={{ textOverflow: 'ellipsis' }}>
Lorem Ipsum is simply dummy text
</Box>
가시성 (Visibility)
<Box component="div" sx={{ visibility: 'visible' }}>
Visible container
</Box>
<Box component="div" sx={{ visibility: 'hidden' }}>
Invisible container
</Box>
공백 (White space)
<Box component="div" sx={{ whiteSpace: 'nowrap' }}>
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</Box>
<Box component="div" sx={{ whiteSpace: 'normal' }}>
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</Box>
API
import { display } from '@mui/system';
| Import name | Prop | CSS property | Theme key |
|---|---|---|---|
displayPrint |
displayPrint |
display |
none |
displayRaw |
display |
display |
none |
overflow |
overflow |
overflow |
none |
textOverflow |
textOverflow |
text-overflow |
none |
visibility |
visibility |
visibility |
none |
whiteSpace |
whiteSpace |
white-space |
none |