Block-level Elements and Block Boxes in CSS

CSSWeb DevelopmentFront End Technology

Block-level elements have their CSS display property set to either ‘block’, ‘list-item’, or ‘table’ and these elements force a line break above and below themselves. Block-level boxes are generated by each block-level element which is a part of the positioning scheme as well as contains child boxes.

Block container boxes contain either block-level boxes and follow block formatting context or contain inline-level boxes and follow inline formatting context. Block boxes is a term used if block-level boxes are also block containers.

Anonymous block boxes are those boxes over which developer has no control. If an inline box contains a block box and the inline content around the block box is enclosed in an anonymous block box.

Example

Let’s see an example for Block-level Elements and Block Boxes −

 Live Demo

<!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>

Output

This will produce the following output −

raja
Published on 07-Jan-2020 15:48:50
Advertisements