DOM 스타일 minWidth 속성은 HTML 문서에서 요소의 최소 너비를 반환하고 수정합니다.
구문
다음은 구문입니다 -
-
minWidth 반환
object.style.minWidth
-
minWidth 수정
object.style.minWidth = “value”
값
여기서 값은 -
일 수 있습니다.| 값 | 설명 |
|---|---|
| 상속 | 상위 요소에서 이 속성 값을 상속합니다. |
| 초기 | 이 속성 값을 기본값으로 설정합니다. |
| 길이 | 길이 단위로 값을 설정합니다. |
| 백분율(%) | 상위 요소의 너비 백분율로 값을 설정합니다. |
예시
스타일 minWidth 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background-image: linear-gradient(to top, #a18cd1 0%, #fbc2eb 100%);
height: 100vh;
}
p {
border: 2px solid #fff;
width: 30%;
}
.btn {
background: coral;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style minWidth 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">Set minWidth</button>
<script>
function add() {
document.querySelector('p').style.minWidth = "300px";
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"최소 너비 설정을 클릭합니다. ” 버튼을 눌러 단락 요소의 최소 너비를 설정합니다.
