CSS min-height 속성을 사용하여 요소의 콘텐츠 상자에 대해 고정된 최소 높이를 정의할 수 있습니다. 이 속성은 높이가 min-height보다 작더라도 요소의 콘텐츠 상자가 더 작아지는 것을 허용하지 않습니다.
구문
CSS min-height 속성의 구문은 다음과 같습니다 -
Selector {
min-height: /*value*/
} 예시
CSS min-height 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<title>CSS min-height Property</title>
</head>
<style>
* {
padding: 2px;
margin:5px;
}
button {
border-radius: 10px;
}
#containerDiv {
width:70%;
margin: 0 auto;
padding:20px;
background-image: linear-gradient(135deg, #dc3545 0%, #9599E2 100%);
text-align: center;
border-radius: 10px;
}
#contentDiv{
min-height:150px;
}
</style>
<body>
<div id="containerDiv">
<div id="contentDiv">
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.
</div>
<button onclick="add()" class="btn">Set minHeight</button>
</div>
<script>
function add() {
document.querySelector('#contentDiv').style.minHeight = "100px";
}
</script>
</body>
</html> 출력
다음은 위 코드의 출력입니다 -
'최소 높이 설정' 버튼을 클릭하기 전에 -

'최소 높이 설정' 버튼을 클릭한 후 -

예시
CSS min-height 속성에 대한 또 다른 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<title>CSS min-height Property</title>
</head>
<style>
* {
padding: 2px;
margin:5px;
}
button {
border-radius: 10px;
}
#containerDiv {
width:70%;
margin: 0 auto;
padding:20px;
background-image: linear-gradient(135deg, #dc3545 0%, #9599E2 100%);
text-align: center;
border-radius: 10px;
}
#contentDiv1, #contentDiv2{
width:50%;
border: 2px solid black;
margin: 0 auto;
}
</style>
<body>
<div id="containerDiv">
<div id="contentDiv1">
This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.
</div>
<div id="contentDiv2">
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy.
</div>
<button onclick="add()" class="btn">Set minHeight</button>
</div>
<script>
function add() {
document.querySelector('#contentDiv1').style.minHeight = "95px";
}
</script>
</body>
</html> 출력
다음은 위 코드의 출력입니다 -
'최소 높이 설정' 버튼을 클릭하기 전에 -

'최소 높이 설정' 버튼을 클릭한 후 -
