DOM 스타일의 textOverflow 속성은 텍스트가 HTML 문서의 요소 컨테이너 외부로 흐를 때 발생해야 하는 일을 반환하고 적용합니다.
구문
다음은 구문입니다 -
-
textOverflow 반환
object.style.textOverflow
-
textOverflow 수정
object.style.textOverflow = “value”
값
여기서 값은 -
일 수 있습니다.| 값 | 설명 |
|---|---|
| 상속 | 상위 요소에서 이 속성 값을 상속합니다. |
| 초기 | 이 속성 값을 기본값으로 설정합니다. |
| 클립 | 넘치는 텍스트를 클리핑합니다. |
| 줄임표 | 요소의 잘린 텍스트를 나타내기 위해 줄임표("...")를 설정합니다. |
| 문자열 | 요소의 잘린 텍스트를 나타내기 위해 주어진 문자열을 설정합니다. |
예시
스타일 textOverflow 속성의 예를 살펴보겠습니다. -
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
}
p {
margin: 1.5rem auto;
border: 3px solid #fff;
width: 400px;
white-space: nowrap;
overflow: hidden;
text-overflow: visible;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style textOverflow Property Example</h1>
<p>
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
</p>
<button onclick="add()" class="btn">Change textOverflow</button>
<script>
function add() {
document.querySelector('p').style.textOverflow = "ellipsis";
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"textOverflow 변경을 클릭합니다. " 버튼을 눌러 넘침 단락 텍스트의 동작을 변경합니다. 여기에 타원이 추가됩니다 -
