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

CSS에서 생성된 상자 유형

<시간/>

시각적 서식 모델에서 처리한 후 문서 트리의 모든 요소에 대해 하나 이상의 상자가 생성됩니다. 생성된 상자에는 연관된 특정 CSS 속성이 있으며 이에 따라 HTML로 렌더링됩니다.

CSS에서 다음 상자가 생성됩니다 −

  • 블록 수준 요소 및 블록 상자
    • 익명 블록 상자
  • 인라인 레벨 요소 및 인라인 상자
    • 익명 인라인 상자

예시

블록 수준 요소 및 블록 상자의 예를 살펴보겠습니다. −

<!DOCTYPE html>
<html>
<head>
<title>CSS Block-level Elements and Block Boxes</title>
<style>
form {
   width:70%;
   margin: 0 auto;
   text-align: center;
}
* {
   padding: 2px;
   box-sizing: border-box;
   /*margin:5px;*/
}
input[type="button"] {
   border-radius: 10px;
}
.child{
   height: 40px;
   width: 100%;
   color: white;
   border: 4px solid black;
}
.child:nth-of-type(1){
   background-color: #FF8A00;
}
.child:nth-of-type(2){
   background-color: #F44336;
}
.child:nth-of-type(3){
   background-color: #C303C3;
}
.child:nth-of-type(4){
   background-color: #4CAF50;
}
.child:nth-of-type(5){
   background-color: #03A9F4;
}
.child:nth-of-type(6){
   background-color: #FEDC11;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>CSS Block-level Elements and Block Boxes</legend>
<div id="container">Color Orange
<div class="child"></div>Color Red
<div class="child"></div>Color Violet
<div class="child"></div>
</div><br>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

CSS에서 생성된 상자 유형

예시

인라인 수준 요소 및 인라인 상자에 대한 예를 살펴보겠습니다. −

<!DOCTYPE html>
<html>
<head>
<title>CSS Inline-level Elements and Inline Boxes</title>
<style>
form {
   width:70%;
   margin: 0 auto;
   text-align: center;
}
* {
   padding: 2px;
}
input[type="button"] {
   border-radius: 10px;
}
.child{
   color: white;
   border: 4px solid black;
}
.child:nth-of-type(1){
   background-color: #FF8A00;
}
.child:nth-of-type(2){
   background-color: #F44336;
}
.child:nth-of-type(3){
   background-color: #C303C3;
}
.child:nth-of-type(4){
   background-color: #4CAF50;
}
.child:nth-of-type(5){
   background-color: #03A9F4;
}
.child:nth-of-type(6){
   background-color: #FEDC11;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>CSS Inline-level Elements and Inline Boxes</legend>
<div><span class="child">Orange</span> Color<span class="child">Red</span> Color<span class="child">Violet</span> Color</div><br>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

CSS에서 생성된 상자 유형