Computer >> 컴퓨터 >  >> 프로그램 작성 >> CSS

CSS의 너비 및 높이 속성

<시간/>

요소의 콘텐츠에 대해서만 높이와 너비를 정의할 수 있지만 이러한 속성에는 여백, 패딩 또는 테두리가 포함되지 않습니다.

구문

CSS 높이 속성의 구문은 다음과 같습니다 -

Selector {
   height: /*value*/
}

CSS 너비 속성의 구문은 다음과 같습니다 -

Selector {
   width: /*value*/
}

너비 및 높이 속성의 예를 살펴보겠습니다. -

예시

<!DOCTYPE html>
<html>
<head>
<title>CSS height and width</title>
</head>
<style>
* {
   padding: 2px;
   margin:5px;
}
button {
   border-radius: 10px;
}
#containerDiv {
   width:70%;
   margin: 0 auto;
   padding:20px;
   background-image: linear-gradient(62deg, #fbab7e 0%, #f7ce68 100%);
   text-align: center;
   border-radius: 10px;
}
#contentDiv2{
   width:200px;
   height: 200px;
   opacity: .5;
   border:1px solid black;
}
</style>
<body>
<div id="containerDiv">
<div id="contentDiv1">
This is paragraph 1 with some dummy text.
</div>
<div id="contentDiv2">
This is paragraph 2 with some dummy text.
</div>
</div>
<script>
</script>
</body>
</html>

출력

CSS의 너비 및 높이 속성

너비 및 높이 속성의 또 다른 예를 살펴보겠습니다. -

예시

<!DOCTYPE html>
<html>
<head>
<title>CSS height and width</title>
<style>
form {
   width:70%;
   margin: 0 auto;
   text-align: center;
}
* {
   padding: 2px;
   margin:5px;
}
input[type="button"] {
   border-radius: 10px;
}
#containerDiv {
   margin: 0 auto;
   height: 150px;
   width:250px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>CSS height and width</legend>
<div id="containerDiv">
<img id="image" src="https://www.tutorialspoint.com/tensorflow/images/tensorflow-mini-logo.jpg">
</div>
</fieldset>
</form>
</body>
</html>

출력

CSS의 너비 및 높이 속성