flexå¸å±å®ç°çåç¹æ°ä»¥å对äºflexå¸å±çæè
ä¹åå¨ä¸æ¬¡é¢è¯ä¸è¢«é®éflexå¸å±è¾æ®éCSSå¸å±çä¼ç¹å¨ä»ä¹å°æ¹ï¼å°±ä¸ªäººç»åèè¨ï¼flexå¸å±æ¯æ®éCSSå¸å±ç®ä¾¿å¾å¤ï¼æ¯å¦æ们è¦è¿è¡ä¸ä¸ªç®åçä¸è¡å个liçæ åºå表çæåï¼è¦æ±ç¸é»liå ç´ é´éèªéåºï¼é¦å°¾å ç´ è¦ä¸ul容å¨æ²¡æé´éï¼ææå¾å¦ä¸ï¼
æ®éCSSå¸å±ä¸ºï¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>1</title>
<style>
#box {
margin: 0px;
padding: 0px;
width: 300px;
height: 300px;
border: 2px solid slategrey;
list-style-type: none;
}
.item {
width: 60px;
height: 60px;
background: salmon;
float: left;
margin-right: 20px;
}
</style>
</head>
<body>
<div>
<ul id="box">
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item" style="margin-right: 0px;"></li>
</ul>
</div>
</body>
</html>
é¦å å°liå ç´ è®¾ç½®floatï¼leftï¼å¨å·²ç¥ul宽度åli宽度çæ åµä¸è¦è®¡ç®å¤ç¸é»liä¹é´çé´é宽度ï¼æ¬ä¾ä¸åæ¯300px-4*60px=60px,å 为å个å ç´ é´æä¸ä¸ªé´éæ 60px*3=20px,è¿æ计ç®åºç¸é»liçé´é宽度ï¼å¹¶ä¸ºliå ç´ è®¾ç½®margin-rightï¼20pxãåä¸è½è®©æåä¸ä¸ªå ç´ å ä¸ºè¶ åºç¶å ç´ å®½åº¦èæ¢è¡ï¼åéå¨æ ç¾ä¸ç´æ¥è®¾ç½®style="margin-right:0px;"è¦çé¦é¨æ ·å¼è¡¨éç设置ï¼æ´ä¸ªè¿ç¨ç¸å½ç¹çã
è¥ä½¿ç¨flexå¸å±ï¼å®ç°è¿ä¸å¸å±å°±æ¾å¾è½»æ¾å¤äºï¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>1</title>
<style>
#box {
margin: 0px;
padding: 0px;
width: 300px;
height: 300px;
border: 2px solid slategrey;
list-style-type: none;
display: flex;
justify-content: space-between;
}
.item {
width: 60px;
height: 60px;
background: salmon;
}
</style>
</head>
<body>
<div>
<ul id="box">
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
</ul>
</div>
</body>
</html>
flexå¸å±ä¸ç®å设置两个å±æ§å°±å¯ä»¥è¾¾å°æ们æ³è¦çææï¼å³ç®ä¾¿ä¹ä¸ç¨è®¡ç®é´é宽度
flexå¸å±å®ç°çåéçä¸ãäºãä¸ãåç¹
ç»æï¼
代ç ï¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>1</title>
<style>
#box {
display: flex;
width: 300px;
height: 300px;
border: 2px solid slategrey;
justify-content: center;
align-items: center;
}
.item {
width: 60px;
height: 60px;
background: salmon;
}
</style>
</head>
<body>
<div id="box">
<div class="item"></div>
</div>
</body>
</html>
ç»æï¼
代ç ï¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>2</title>
<style>
#box {
display: flex;
width: 300px;
height: 300px;
border: 2px solid slategrey;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.item {
width: 60px;
height: 60px;
background: salmon;
}
</style>
</head>
<body>
<div id="box">
<div class="item"></div>
<div class="item"></div>
</div>
</body>
</html>
ç»æï¼
代ç ï¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>3</title>
<style>
#box {
display: flex;
width: 300px;
height: 300px;
border: 2px solid slategrey;
flex-direction: column;
justify-content: space-between;
}
.item {
width: 60px;
height: 60px;
background: salmon;
}
.item:nth-child(2) {
align-self: center;
}
.item:nth-child(3) {
align-self: flex-end;
}
</style>
</head>
<body>
<div id="box">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</body>
</html>
ç»æï¼
代ç ï¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>4</title>
<style>
#box {
display: flex;
width: 300px;
height: 300px;
border: 2px solid slategrey;
flex-wrap: wrap;
align-content: space-around;
}
.item-box {
display: flex;
flex-basis: 100%; /*å
³é®ç设置*/
justify-content: space-around;
}
.item {
width: 60px;
height: 60px;
background: salmon;
}
</style>
</head>
<body>
<div id="box">
<div class="item-box">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="item-box">
<div class="item"></div>
<div class="item"></div>
</div>
</div>
</body>
</html>
上一篇: 如何在C#项目中使用NHibernate