css3flex布局实现平均分配元素的⽰例代码本⽂主要介绍了css3 flex布局实现平均分配元素,给⾃⼰留个笔记,也分享给⼤家,具体如下:
例⼦⼀:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex 布局</title>
<style>
*{
padding:0;
margin:0;
}
body,html{
height: 100vh;
min-width: 800px;
}
.container{
display:flex;
flex-wrap:wrap;
display: -webkit-flex; /* Safari */
}
.container>.item{
border: 1px solid black;
flex:1;
height:100px;
background: #abcdef;
}
</style>
</head>
<body>
<div class="container">
<div class="item"></div>
<main class="item"></main>
<div class="item"></div>
</div>
</body>
</html>
例⼦⼆:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex 布局</title>
<style>
*{
padding:0;
margin:0;
box-sizing: border-box;
}
body,html{
width: 100%;
height: 100vh;
min-width: 800px;
display:flex;
display: -webkit-flex; /* Safari */
justify-content: center;
align-items: center;
}
.container{
width: 300px;
height: 300px;
display:flex;
display: -webkit-flex; /* Safari */
flex-wrap: wrap;
}
.container>.item{
flex:0 0 33.3%;
height:100px;
background: #abcdef;
border: 1px solid red;
}
main{
flex:0 0 33.3%;
height:100px;
background-color: #ccc;
border: 1px solid red;
}
</style>
</head>
<body>
<div class="container">
<div class="item">left</div>
<main>main</main>
<div class="item">right</div>
<div class="item">left</div>
<main>main</main>
<div class="item">right</div>
<div class="item">left</div>
<main>main</main>
<div class="item">right</div>
</div>
</body>
</html>
flex:0 0 33.3% 相当于flex-basis:33.3%,使每⼀个元素的宽度占外层容器的33.3%,因此每⾏最多能够排开三个元素。flex-wrap:wrap 表⽰每⾏填满时会⾃动换⾏。
例⼦三:
<!DOCTYPE html>flex布局详细讲解
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex 布局</title>
<style>
*{
padding:0;
margin:0;
box-sizing: border-box;
}
body,html{
width: 100%;
height: 100vh;
min-width: 800px;
display:flex;
display: -webkit-flex; /* Safari */
justify-content: center;
align-items: center;
}
.container{
width: 300px;
height: 300px;
margin: 50px;
display:flex;
display: -webkit-flex; /* Safari */
flex-wrap: wrap;
justify-content: space-between;
}
.container>.item{
flex:0 0 30%;
height:90px;
background: #abcdef;
border: 1px solid red;
}
main{
flex:0 0 30%;
height:90px;
background-color: #ccc;
border: 1px solid red;
}
</style>
</head>
<body>
<div class="container">
<div class="item">left</div>
<main>main</main>
<div class="item">right</div>
<div class="item">left</div>
<main>main</main>
<div class="item">right</div>
<div class="item">left</div>
<main>main</main>
<div class="item">right</div>
</div>
</body>
</html>
justify-content:space-between表⽰主轴⽅向的多余空间平均分配在两两item之间。
到此这篇关于css3 flex布局实现平均分配元素的⽰例代码的⽂章就介绍到这了,更多相关flex平均分配元素内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章,希望⼤家以后多多⽀持!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论