
批改狀態(tài):合格
老師批語:能理解到這個地步不簡單, 畢竟昨晚咱們才開始進行組件分解... , 今晚更精彩, 不要錯過
詳細說明在注釋哦!嘻嘻!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex item屬性</title>
<style>
*{
margin: 0;
padding: 0;
}
.container{
width: 400px;
height: 100px;
border: 1px dashed;
background-color: #cccccc;
display: flex;
}
/*flex 彈性盒子的 子元素(item/項目)的屬性*/
.container >.item{
width: 100px;
height: 30px;
border: 1px dashed red;
background-color: wheat;
}
/* 1- 在容器中使用 order 屬性,控制子元素(item)的排列先后順序;*/
.container >:first-child{
order: 3;
}
.container >:last-child{
order: 1;
}
/* 2- 在容器中使用,align-self 屬性,單獨自定義某一個子元素,在交叉軸上的對齊方式;*/
.container >:nth-child(2){
align-self: flex-end;
background-color: #9a6e3a;
}
/*3- 子元素(item/項目)中,關于剩余空間部分的屬性中。*/
/*3.1 flex-basis ,子元素(item),在分配主軸剩余空間之前的“基礎寬度”
默認值:flex-basis:auto,也就是顯示寬度是“原始的寬度值: .container >.item{ width: 100px; }”;
flex-basis:80px ,重新定義,子元素的顯示寬度;
flex-basis:20% ,
min-width:120px ,子元素(item)的最小寬度;
*/
.container >.item{
flex-basis: 30%;
min-width: 120px;
}
/*3.2 flex-grow ,表示是否允許子元素(item)沿著主軸方向,以 flex-basis 屬性為基礎進行擴展。
并且,規(guī)定將主軸剩余空間分配到項目上的比例;
默認值:flex-grow:0 ,不允許擴展;
若 flex-grow:1 ,則表示將剩余空間平局分配給各個子元素(item);
若 flex-grow:0.2 ,則表示將余空間的20%,分別增加給子元素;
*/
.container >.item{
flex-grow: 1;
}
/*3.3 flex-shrink ,與flex-grow雷同,只不過是控制子元素沿主軸方向,以flex-basis 屬性為基礎進行收縮。
需要注意的是,在進行收縮的時候,需要考慮最小寬度,并且只有當子元素的寬度總和超出容器寬度時,才能起效;
默認值:flex-shrink:1 ,
flex-shrink 不接受負值;
flex-shrink :0 ,表示不進行收縮;
*/
.container >.item{
flex-shrink: 1;
}
/*3.4 簡寫 flex: flex-grow flex-shrink flex-basis,
默認值:flex:0(不擴展) 1(可收縮) auto(自適應寬度);
*/
.container >.item{
/*flex:auto 等價于 flex:1 1 auto ,表示【可擴展,可收縮,自適應寬度】
flex:2 等價于 flex:1 1 auto ,表示【可擴展,可收縮,自適應寬度】
flex:none 等價于 flex:0 0 auto ,表示【不可擴展 不可收縮,自適應寬度】
*/
flex:auto;
}
</style>
</head>
<body>
<div class="container">
<span class="item">1</span>
<span class="item">2</span>
<span class="item">3</span>
</div>
</body>
</html>
抄寫
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>組件頁面練習</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<!--頁面頭部組件-->
<div class="public-header">
<a href="">網站首頁</a>
<a href="">專題</a>
<a href="">網站導航</a>
<a href="">二手商品</a>
<a href="">討論區(qū)</a>
<span>
<a href=""><i class="iconfont"></i>登錄</a>
<a href="">免費注冊</a>
</span>
</div>
<!--頁面標題組件-->
<div class="public-headline">
<span>二手拍賣</span>
</div>
</body>
</html>
/*引入字體圖標庫*/
@font-face {
font-family: 'iconfont';
src: url('../../../1220/css/font/iconfont.eot');
src: url('../../../1220/css/font/iconfont.eot?#iefix') format('embedded-opentype'),
url('../../../1220/css/font/iconfont.woff2') format('woff2'),
url('../../../1220/css/font/iconfont.woff') format('woff'),
url('../../../1220/css/font/iconfont.ttf') format('truetype'),
url('../../../1220/css/font/iconfont.svg#iconfont') format('svg');
}
.iconfont {
font-family: "iconfont", serif !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/*所有頁面初始化樣式設置*/
*{
margin: 0;
padding: 0;
/*調試參考線*/
/* outline: 1px dashed red;*/
}
body{
font-size: 13px;
color: #555555;
background-color: #efefef;
}
a{
font-size: 13px;
color: #404040;
/*去掉超鏈接下劃線*/
text-decoration: none;
}
li{
list-style: none;
}
/*引入公共初始化標簽樣式文件*/
@import "public_reset.css";
/*頭部*/
.public-header{
height: 44px;
background-color: black;
padding: 0 20px;
/*轉化為彈性盒子容器*/
display: flex;
flex-flow: row nowrap;
}
/*統(tǒng)一設置容器下的 a 標簽項目*/
.public-header >a{
line-height: 44px;
text-align: center;
padding: 0 10px;
color: #cccccc;
}
.public-header >a:hover{
background-color: #fff;
color: black;
}
/*頭部右側內容 right*/
.public-header >span{
line-height: 44px;
text-align: center;
margin-left: auto;
}
.public-header >span a{
color: #cccccc;
padding: 0 10px;
}
/*設置右側登錄圖標*/
.public-header >span a i{
font-size: 16px;
color: #cccccc;
padding-right: 10px;
}
/*引入公共初始化標簽樣式文件*/
@import "public_reset.css";
.public-headline{
padding: 30px;
text-align: center;
}
.public-headline >span{
font-size: 30px;
/*字體粗體樣式*/
font-weight: bolder;
padding-bottom: 7px;
border-bottom: 3px solid red;
}
@import "Components/public/public_reset.css";
@import "Components/public/public_header.css";
@import "Components/public/public_headline.css";
1、需要較為清晰的將頁面進行合理的拆分,以保障組件的復用性,復用性是組件開發(fā)最大的價值體現(xiàn);
2、組件的命名要規(guī)范、清晰,并且具備很好的可讀性,只有這樣才能提高代碼的可維護性,從而降低維護成本;
3、css的類名需要層級明確,防止因為意外的樣式覆蓋;
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號