
CSS弹性盒模型flex在布局中的应用
元素居中
【1】伸缩容器上使用主轴对齐justify-content和侧轴对齐align-items
<style>.parent{
display: flex;
justify-content: center;
align-items: center;}</style><div>
<div>DEMO</div> </div>
【2】在伸缩项目上使用margin:auto
<style>.parent{
display: flex;}.in{
margin: auto;}</style><div>
<div>DEMO</div> </div>
两端对齐
<style>.parent{
display: flex;
justify-content:space-between
}
</style><div>
<div>DEMO</div>
<div>DEMO</div>
<div>DEMO</div>
<div>DEMO</div>
</div>
底端对齐
<style>.parent{
display: flex;
align-items: flex-end;
}
</style><div>
<div>DEMO</div>
<div>DEMO</div>
<div>DEMO</div>
<div>DEMO</div>
</div>
输入框按钮
<style>.inputBox{
display: flex;
width: 250px;}.inputBox-ipt{
flex: 1;}
</style><div>
<input>
<button>按钮</button>
</div>
等分布局
<style>body,p{margin: 0;}.parent{
display: flex;}.child{
flex:1;
height: 100px;}.child + .child{
margin-left: 20px;}
</style><div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
多列自适应布局
<style>p{margin: 0;}.parent{display: flex;}.left,.center{margin-right: 20px;}.right{flex: 1;}</style><div>
<div>
<p>left</p>
<p>left</p>
</div>
<div>
<p>center</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13837" title="htmlq 命令行 HTML 内容提取器,支持 CSS 选择器"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20d3191a227.jpg" alt="htmlq 命令行 HTML 内容提取器,支持 CSS 选择器" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13837" title="htmlq 命令行 HTML 内容提取器,支持 CSS 选择器" class="overflowclass">htmlq 命令行 HTML 内容提取器,支持 CSS 选择器</a>
<p class="overflowclass">htmlq 是一个命令行工具,使用 CSS 选择器从 HTML 中提取内容,相当于 jq 的 HTML 版本。该工具使用 Rust 编写,允许你通过 CSS 选择器将 HTML 管道化,直接从终端提取文本、属性和结构化内容。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13837" title="htmlq 命令行 HTML 内容提取器,支持 CSS 选择器" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<p>center</p>
</div>
<div>
<p>right</p>
<p>right</p>
</div>
</div>
悬挂布局
<style>
.box{
display: flex;
background-color: lightgrey;
width: 300px;}.left{
margin-right: 20px;
background-color: lightblue;
height: 30px;}.main{
flex:1;}
</style><div>
<div>左侧悬挂</div>
<div>主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容</div>
</div>
全屏布局
<style>body,p{margin: 0;}body,html,.parent{height: 100%;}.parent{
display: flex;
flex-direction: column;}.top,.bottom{
height: 50px;}.middle{
display: flex;
flex: 1;}.left{
width: 100px;
margin-right: 20px;}.right{
flex: 1;
overflow: auto;}.right-in{
height: 1000px;}</style><div>
<div>
<p>top</p>
</div>
<div>
<div>
<p>left</p>
</div>
<div>
<div>
<p>right</p>
</div>
</div>
</div>
<div>
<p>bottom</p>
</div>
</div>
以上就是CSS弹性盒模型flex在布局中的应用的全部内容。
相关参考:php中文网
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










