Computer >> Computer tutorials >  >> Programming >> CSS

Inline-level Elements and Inline Boxes in CSS


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

Inline boxes are boxes which have their content follow inline formatting context. Inline boxes are split into a number of inline boxes whilst those inline boxes that are never split are called atomic inline-level boxes.

Anonymous inline boxes are those boxes over which developer has no control. If a block box contains some bare text and other inline-level boxes, then the bare text around inline-level boxes follows inline formatting context and is enclosed in anonymous inline boxes.

Example

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

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

Output

This will produce the following output −

Inline-level Elements and Inline Boxes in CSS