知識點記錄:css
1.flex-flow屬性用於設置靈活項目的佈局方式,是 flex-direction 和 flex-wrap的複合屬性,書寫格式 flex-flow:direction wraphtml
flex-direction屬性值:佈局
flex-flow:row,伸縮項目在flexbox中 由左向右水平排列,row-reverse爲相反方向flex
flex-flow:column,伸縮項目在flexbox中 由上向下垂直排列。column-reverse爲相反方向flexbox
flex-wrap屬性值:spa
nowrap,靈活項目不拆行或拆列orm
wrap,靈活項目在必要的時候拆行或拆列htm
wrap-reverse,靈活項目必要時候按照相反順序拆行或拆列blog
2.設置元素水平垂直居中ip
一種狀況,元素有明確的高度
① 絕對定位+ 負margin,元素屬性值設置:position: absolute;left:50%;top:50%;margin-left: -w/2(元素寬度一半);margin-top: -h/2(元素高度一半);
② 僅適用絕對定位,元素屬性值設置:position: absolute;top: 0;right: 0;bottom: 0;left: 0;margin: auto;
二種狀況,元素沒有肯定的高度
① 絕對定位+ transform,元素屬性值設置:position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
② 模擬 table佈局,父元素屬性設置:display:table;,子元素屬性設置:display:table-cell;text-align:center;vertical-align:middle;,table在佈局方面一般不推薦使用
③ 使用僞元素建立居中內容
3.彈性盒子的寬度一般使用百分比進行設置,不設置固定高度,由內容填充後自動撐開,元素內靈活項目默認水平排列
/*>>>>>>>>>>>>>>JS代碼<<<<<<<<<<<<<<<*/ var click=document.getElementById("click"); var imgBox=document.getElementById("imgBox"); var li=click.getElementsByTagName("li"); function change(i){ if(i==0){ imgBox.src="../images/chuangPic/banner1.png" }else if(i==1){ imgBox.src="../images/chuangPic/banner2.jpg" }else if(i==2){ imgBox.src="../images/chuangPic/banner3.jpg" }else if(i==3){ imgBox.src="../images/chuangPic/banner4.jpg" }else if(i==4){ imgBox.src="../images/chuangPic/banner5.jpg" } } /*>>>>>>>>>>>>>>>>CSS代碼<<<<<<<<<<<<<<<<*/ body{ margin: 0; padding: 0; } /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>導航欄設置<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ .nav{ width: 100%; height: 50px; background-color: rgb(0,127,95); display: flex; position: fixed; z-index: 9; } .city{ width: 80px; height: 50px; font-size: 18px; color: #ffffff; background-color: #ff6700; line-height: 50px; text-align: center; } .city a{ color: #ffffff; text-decoration: none; } .head{ height: 50px; line-height: 50px; color: #ffffff; font-size: 20px; letter-spacing: 2px; flex-grow: 1; text-align: center; } .search button{ width: 50px; height: 50px; color: #ffffff; font-size: 24px; line-height: 50px; background-color: rgba(0,0,0,0); border: 0; cursor: pointer; } /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>輪播圖設置<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ .carousel{ width: 100%; position: relative; } .carousel img{ width: 100%; } .click{ width: 100%; height: 5%; bottom: 5%; position: absolute; } .click ul{ width: 60%; height: 100%; margin: 0 auto; padding: 0; display: flex; justify-content: space-between; } .click ul>li{ list-style-type: none; width: 18%; height: 100%; background-color: rgb(0,127,95); } /*>>>>>>>>>>>>>>>>html代碼<<<<<<<<<<<<<<<<<*/ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-with, initial-scale=1"> <title>移動端</title> <link rel="stylesheet" href="css/chuangstyle.css"/> <link rel="stylesheet" href="css/chuangicon/iconfont.css"> </head> <body> <div class="nav"> <div class="city">成都 <a href="#" class="iconfont"></a></div> <div class="head">縱橫千里點餐系統</div> <div class="search"> <button class="iconfont"></button> </div> </div> <div class="carousel"> <img src="images/chuangpic/banner1.png" alt="" id="imgBox"/> <div class="click"> <ul id="click"> <li onclick="change(0)"></li> <li onclick="change(1)"></li> <li onclick="change(2)"></li> <li onclick="change(3)"></li> <li onclick="change(4)"></li> </ul> </div> </div> <script src="css/index.js"></script> </body> </html>