CSS 中的内联元素和内联框

cssweb developmentfront end technology更新于 2025/1/10 21:32:17

内联元素的 CSS display 属性设置为 ‘inline’、‘inline-table’ 或 ‘inline-block’,并且这些元素不会强制在其上方和下方换行。内联框由每个内联元素生成,这些内联元素是定位方案的一部分,并且包含子框。

内联框是指其内容遵循内联格式化上下文的框。内联框会被拆分成多个内联框,而那些永远不会拆分的内联框被称为原子内联框。

匿名内联框是指开发人员无法控制的框。如果一个块级框包含一些裸文本和其他行内框,则行内框周围的裸文本将遵循行内格式化上下文,并被包含在匿名行内框中。

示例

让我们看一个行内元素和行内框的示例 −

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

输出

这将产生以下输出 −


相关文章


有用资源