阅读 170

携程移动端静态首页flex布局

携程移动端静态首页flex布局(弹性布局)

主要知识点:flex布局&属性选择器&阴影&背景渐变

HTML结构


    
    
我 的

热门活动
获取更多福利>

思路复盘

顶部搜索模块:一个.search-index大盒子里有两个小盒子(.search&.user)

*大盒子设置display:flex;.search盒子设置flex:1;保证页面拉大时搜索框跟着变大

*小盒子里的图标使用伪元素选择器制作,简化HTML结构

局部导航栏模块:一个.local-nav的大盒子里放五个a,每个a里面装两个span盒子

*大盒子设置display:flex;每个a盒子设置flex:1;使大盒子被平均分成五份,每个a各占一份

*每个a盒子也设置display:flex;&flex-direction:column;&align-items:center;使a盒子里面的内容水平居中

其他的几个主要的盒子思路都和这个差不多了

CSS代码

body {
    max-width: 540px;
    min-width: 320px;
    margin: 0 auto;
    font: normal 14px/1.5 Tahoma, Verdana;
    color: #000;
    background: #f2f2f2;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

a {
    text-decoration: none;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

li {
    list-style: none;
}

.search-index {
    display: flex;
    width: 100%;
    /*固定的盒子要有宽度 */
    height: 44px;
    position: fixed;
    top: 0;
    left: auto;
    max-width: 540px;
    min-width: 320px;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    background-color: #f6f6f6;
}

.search-index .search {
    flex: 1;
    margin: 5px 5px;
    height: 28px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin: 7px 10px;
    line-height: 26px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
    font-size: 12px;
    color: #666;
}

.search-index .search::before {
    content: "";
    display: inline-block;
    width: 15px;
    height: 15px;
    background: url(../imgs/sprite.png) no-repeat -59px -278px;
    background-size: 104px auto;
    margin: 5px 8px;
    vertical-align: middle;
}

.search-index .user {
    width: 44px;
    height: 44px;
    color: #2eaae0;
    font-size: 12px;
    text-align: center;
}

.search-index .user::before {
    content: "";
    display: block;
    width: 24px;
    height: 26px;
    background: url(../imgs/sprite.png) no-repeat -59px -193px;
    background-size: 104px auto;
    margin: 3px auto 0 auto;
}


/* focus模块 */

.focus {
    margin-top: 47px;
}

.focus img {
    width: 100%;
}


/* 局部导航栏 */

.local-nav {
    display: flex;
    height: 64px;
    background-color: #fff;
    border-radius: 8px;
    margin: 3px 5px;
}

.local-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #222;
    font-size: 12px;
}

.local-nav span[class^="local-nav-icon"] {
    width: 32px;
    height: 32px;
    background: url(../imgs/localnav_bg.png) no-repeat 0 0;
    background-size: 32px auto;
    margin: 9px 0 5px 0;
}

.local-nav a .local-nav-icon2 {
    background-position: 0 -32px;
}

.local-nav a .local-nav-icon3 {
    background-position-y: -64px;
}

.local-nav a .local-nav-icon4 {
    background-position-y: -96px;
}

.local-nav a .local-nav-icon5 {
    background-position-y: -128px;
}


/* 主导航栏模块 */

nav {
    overflow: hidden;
    height: 270px;
    margin: 0 4px 5px 4px;
    border-radius: 8px;
}

nav .nav-common {
    display: flex;
    height: 90px;
    background: -webkit-linear-gradient(left, #FA5A55, #FA994D);
    margin-bottom: 5px;
}

nav .nav-common:nth-child(2) {
    background: -webkit-linear-gradient(left, #4B90ED, #53BCED);
}

nav .nav-common:nth-child(3) {
    background: -webkit-linear-gradient(left, #34C2A9, #6CD559);
}

nav .nav-common li {
    flex: 1;
    display: flex;
    border-left: 1px solid #fff;
    border-bottom: 1px solid #fff;
}

nav .nav-common li a {
    flex: 1;
    text-align: center;
    line-height: 45px;
    text-shadow: 1px 1px rgba(0, 0, 0, 0.45);
    font-size: 12px;
    color: #fff;
}

nav .nav-common li:nth-child(1) a {
    background: url(../imgs/hotel.png) no-repeat bottom center;
    background-size: 121px auto;
}

nav .nav-common:nth-child(2) li:nth-child(1) a {
    background: url(../imgs/plane.png) no-repeat bottom center;
    background-size: 121px auto;
}

nav .nav-common:nth-child(3) li:nth-child(1) a {
    background: url(../imgs/vacation.png) no-repeat bottom center;
    background-size: 121px auto;
}

nav .nav-common li:nth-child(n+2) {
    display: flex;
    flex-direction: column;
}

nav .nav-common li:nth-child(n+2) a {
    flex: 1;
    height: 45px;
}

nav .nav-common li:nth-child(n+2) a:nth-child(1) {
    border-bottom: 1px solid #fff;
}


/* 生活服务模块 */

.life-sevice {
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    background-color: #fff;
    margin: 0 4px 5px 4px;
    height: 115px;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2);
}

.life-sevice .rol1,
.rol2 {
    flex: 1;
    display: flex;
}

.life-sevice a {
    flex: 20%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 8px 0 0 0;
    color: #000;
    font-size: 12px;
}

.life-sevice div a span {
    flex: 1;
}

.life-sevice div a span:nth-child(1) {
    width: 28px;
    height: 28px;
    background: url(../imgs/subnav-bg.png) no-repeat;
    background-size: 28px auto;
}

.life-sevice .rol1 a:nth-child(2) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -30px;
    background-size: 28px auto;
}

.life-sevice .rol1 a:nth-child(3) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -64px;
    background-size: 28px auto;
}

.life-sevice .rol1 a:nth-child(4) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -100px;
    background-size: 28px auto;
}

.life-sevice .rol1 a:nth-child(5) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -133px;
    background-size: 28px auto;
}

.life-sevice .rol2 a:nth-child(1) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -163px;
    background-size: 28px auto;
}

.life-sevice .rol2 a:nth-child(2) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -198px;
    background-size: 28px auto;
}

.life-sevice .rol2 a:nth-child(3) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -228px;
    background-size: 28px auto;
}

.life-sevice .rol2 a:nth-child(4) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -262px;
    background-size: 28px auto;
}

.life-sevice .rol2 a:nth-child(5) span:nth-child(1) {
    background: url(../imgs/subnav-bg.png) no-repeat 0 -290px;
    background-size: 28px auto;
}


/* 热门活动模块 */

.hot {
    border-top: 1px solid #ddd;
    margin-bottom: 5px;
    background-color: #fff;
}

h2 {
    height: 31px;
    font-size: 12px;
    border-bottom: 1px solid #ededed;
}

h2 .left {
    text-indent: -999px;
    overflow: hidden;
    /* 搜索引擎优化 */
    float: left;
    width: 79px;
    height: 18px;
    margin-left: 5px;
    background: url(../imgs/hot.png) no-repeat 0 -18px;
    background-size: 79px auto;
}

h2 a {
    float: right;
    padding: 3px 5px;
    margin: -3px 8px 0 0;
    border-radius: 15px;
    color: #fff;
    font-weight: 400;
    background: -webkit-linear-gradient(left, #FF506C, #FF6BC6);
}

.hot>div {
    display: flex;
}

.hot>div a {
    flex: 1;
    border-bottom: 1px solid #ededed;
}

.hot>div a:nth-child(1) {
    border-right: 1px solid #ededed;
}

.hot>div a img {
    width: 100%;
}


/* 底部模块 */

.banner {
    display: flex;
    background-color: #fff;
    height: 50px;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    text-align: center;
    box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2)
}

.banner a {
    flex: 1;
    display: flex;
    justify-items: center;
    align-items: center;
    flex-direction: column;
    font-size: 12px;
    color: #222;
}

.banner a span {
    flex: 1;
}

.banner a span:nth-child(1) {
    width: 25px;
    height: 24px;
    margin-top: 5px;
    background: url(../imgs/sprite.png) no-repeat -59px -170px;
    background-size: 104px auto;
}

.banner a:nth-child(2) span:nth-child(1) {
    background: url(../imgs/sprite.png) no-repeat -59px -150px;
    background-size: 104px auto;
}

.banner a:nth-child(3) span:nth-child(1) {
    background: url(../imgs/sprite.png) no-repeat -59px -307px;
    background-size: 104px auto;
}

.detail {
    text-align: center;
    font-size: 12px;
    margin-top: 10px;
}

.detail a {
    color: #222;
}

.detail p {
    color: #666;
    margin: 0;
}

知识点浅解

背景线性渐变:background:linear-gradient(起始方向,颜色1,颜色2,颜色3,…);

盒子阴影:box-shadow:水平阴影的位置,垂直阴影的位置,阴影的模糊范围,阴影颜色;

eg:box-shadow:1px,1px,4px,rgba(0,0,0,0.2);

效果展示

原文:https://www.cnblogs.com/ben-studying/p/14811265.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐