• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

web前端案例——携程网首页flex弄一个

武飞扬头像
露露不要掉头发
帮助3

精灵图笔记:
精灵图是把需要的小图片拼接到一张图片上,可以减少请求服务器的次数,让网页加载速度变快。
二倍图:需要50x50(css),如果直接放进去,那么移动端会放大2倍,变成100x100css,图片变模糊。所以准备一张100x100的图片,然后缩小为50x50的图片,就不会变模糊。

c3盒子模型笔记:
两种盒模型:content-box和border-box。
border-box是常用的盒模型,声明他之后便不用考虑加边框后盒子变形的问题。但是在设置内容文本垂直居中时,行高不可以再等于盒子上下外边距的高度,而是应该等于盒子上下内边距的高度。即行高=盒子高度-上下边框宽度。

背景渐变笔记:
背景渐变有自己的固定语句,即:linear-gradient(起始位置,颜色1,颜色2)
但是由于兼容问题,需要在前面加上浏览器私有前缀。

浏览器前缀 浏览器
-webkit- Google chrome,Safari,android browser
-moz- firefox
-o- Opera
-ms- Internet Explorer,Edge
-khtml- konqueror

flex换行布局笔记:
flex-wrap:“wrap”;即可换行。
用justify-content(父级)多种布局:
flex-start起始位置对齐,
flex-end结束位置对齐,
center行中间位置对齐,
space-between平均地分布在行里,
space-around会平均地分布在行里,两端保留子元素与子元素之间间距大小的一半。

效果图:
学新通
代码:
html部分

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no,maximum-scale=1.0,minimum-scale=1.0">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/index.css">
    <title>携程在手,说走就走</title>
</head>

<body>
    <!-- 搜索模块 -->
    <div class="search-index">
        <div class="search">搜索:目的地/酒店/景点/航班号</div>
        <a href="#" class="user">我 的</a>
    </div>
    <!-- 焦点图模块 -->
    <div class="focus">
        <img src="upload/focus.jpg" alt="">
    </div>
    <!-- 局部导航栏 -->
    <ul class="local-nav">
        <li><a href="#" title="景点·玩乐"><span class="local-nav-icon-icon1"></span> 
            <span>景点·玩乐</span></a></li>
        <li><a href="#" title="周边游"><span class="local-nav-icon-icon2"></span> 
            <span>周边游</span></span></a></li>
        <li><a href="#" title="美食林"><span class="local-nav-icon-icon3"></span> 
            <span>美食林</span></span></a></li>
        <li><a href="#" title="一日游"><span class="local-nav-icon-icon4"></span> 
            <span>一日游</span></span></a></li>
        <li><a href="#" title="当地攻略"><span class="local-nav-icon-icon5"></span> 
            <span>当地攻略</span></span></a></li>
    </ul>
    <!-- 主导航栏 -->
    <nav>
        <div class="nav-common">
            <div class="nav-items">
                <a href="#">酒店</a>
            </div>
            <div class="nav-items">
                <a href="#">海外酒店</a>
                <a href="#">特价酒店</a>
            </div>
            <div class="nav-items">
                <a href="#">海外酒店</a>
                <a href="#">特价酒店</a>
            </div>
        </div>
        <div class="nav-common">
            <div class="nav-items">
                <a href="#">机票</a>
            </div>
            <div class="nav-items">
                <a href="#">火车票</a>
                <a href="#">特价机票</a>
            </div>
            <div class="nav-items">
                <a href="#">汽车票·船票</a>
                <a href="#">专车·租车</a>
            </div>
        </div>
        <div class="nav-common">
            <div class="nav-items">
                <a href="#">旅游</a>
            </div>
            <div class="nav-items">
                <a href="#">门票</a>
                <a href="#">目的地攻略</a>
            </div>
            <div class="nav-items">
                <a href="#">邮轮旅行</a>
                <a href="#">定制旅行</a>
            </div>
        </div>
    </nav>
    <!-- 侧导航栏入口 -->
    <ul class="subnav-entry">
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>WiFi电话卡</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>保险·签证</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>外币兑换</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>购买</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>当地向导</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>自由行</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>境外玩乐</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>礼品卡</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>信用卡</span>

            </a>
        </li>
        <li>
            <a href="#">
                <span class="subnav-entry-icon"></span>
                <span>更多</span>

            </a>
        </li>


    </ul>
    <!-- 销售模块 -->
    <div class="sales-box">
        <div class="sales-hd">
            <h2>热门活动</h2>
            <a href="#">获取更多福利</a>
        </div>
        <div class="sales-bd">
            <div class="row">
                <a href="#">
                    <img src="upload/pic1.jpg" alt="">
                </a>
                <a href="#">
                    <img src="upload/pic2.jpg" alt="">
                </a>
            </div>
            <div class="row">
                <a href="#">
                    <img src="upload/pic3.jpg" alt="">
                </a>
                <a href="#">
                    <img src="upload/pic4.jpg" alt="">
                </a>
            </div>
            <div class="row">
                <a href="#">
                    <img src="upload/pic5.jpg" alt="">
                </a>
                <a href="#">
                    <img src="upload/pic6.jpg" alt="">
                </a>
            </div>

        </div>
    </div>
</body>

</html>
学新通

css部分:

body {
    max-width: 540px;
    min-width: 320px;
    margin: 0 auto;
    font: normal 14px/1.5 Tahoma, "Lucida Grande", Verdana, "Microsoft Yahei", STXihei, hei;
    color: #000;
    background: #f2f2f2;
    overflow-x: hidden;
    /* 不显示水平显示条 */
    -webkit-tap-highlight-color: transparent;
    /* 防止被点击之后背景高亮 */
}


/* ul有默认的margin和padding */

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

a {
    text-decoration: none;
    color: #222;
}

div {
    box-sizing: border-box;
}


/* 搜索模块 */

.search-index {
    display: flex;
    position: fixed;
    top: 0;
    /* 固定的盒子不能用margin:auto来居中 */
    left: 50%;
    /* 兼容老浏览器 */
    -webkit-transform: translate(-50%);
    transform: translate(-50%);
    /* 固定的盒子必须有宽度 ,因为它依附的是浏览器*/
    width: 100%;
    min-width: 320px;
    max-width: 540px;
    height: 44px;
    background-color: #f6f6f6;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
}

.search {
    position: relative;
    height: 26px;
    line-height: 24px;
    padding-left: 25px;
    border: 1px solid #ccc;
    flex: 1;
    /* 左侧自适应 */
    font-size: 12px;
    color: #666;
    margin: 7px 10px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
}

.search::before {
    content: "";
    position: absolute;
    /* 改成绝对定位则不会把其他元素挤掉下来,之前用的是转化为块级元素再给予大小 */
    top: 0;
    left: 0;
    width: 15px;
    height: 15px;
    background: url(../images/sprite.png) no-repeat -59px -279px;
    background-size: 104px auto;
    margin: 5px;
}

.user {
    width: 44px;
    height: 44px;
    text-align: center;
    color: #2eaae0;
}

.user::before {
    content: "";
    background: url(../images/sprite.png) no-repeat -59px -194px;
    display: block;
    width: 23px;
    height: 23px;
    background-size: 104px auto;
    margin: 4px auto -2px;
    /* 上,左右,下 ,让文字上移*/
}


/* 因为搜索栏是固定定位,所以浮起来不占位置,需要把焦点图下移 */

.focus {
    padding-top: 44px;
}

.focus img {
    width: 100%;
}

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

.local-nav li {
    flex: 1;
}

.local-nav a {
    display: flex;
    flex-direction: column;
    /* 侧轴居中对齐  因为是单行*/
    align-items: center;
    font-size: 12px;
}


/* 属性选择器 */

.local-nav li [class^="local-nav-icon"] {
    width: 32px;
    height: 32px;
    background-color: pink;
    margin-top: 8px;
    background: url(../images/localnav_bg.png) no-repeat 0 0;
    background-size: 32px auto;
}

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

.local-nav li .local-nav-icon-icon3 {
    background-position: 0 -64px;
}

.local-nav li .local-nav-icon-icon4 {
    background-position: 0 -96px;
}

.local-nav li .local-nav-icon-icon5 {
    background-position: 0 -128px;
}


/* 不用给nav高度,让盒子把它撑开就行 */

nav {
    border-radius: 8px;
    margin: 0 4px 3px;
    overflow: hidden;
    /* nav是有圆角但是里面的div没有,所以用overflow让其显现出来 */
}

.nav-common {
    display: flex;
    height: 88px;
}

.nav-common:nth-child(2) {
    margin: 3px 0;
}

.nav-items {
    /* 相对于父类 */
    flex: 1;
    /* 相对于子类 */
    display: flex;
    /* 轴的方向定义应该在父类 */
    flex-direction: column;
}

.nav-items a {
    flex: 1;
    text-align: center;
    line-height: 44px;
    color: #fff;
    font-size: 14px;
    /* 文字阴影 */
    text-shadow: 1px 1px rgba(0, 0, 0, .2);
}

.nav-items a:nth-child(1) {
    border-bottom: 1px solid #fff;
}

.nav-items:nth-child(1) a {
    border: 0;
    background: url(../images/hotel.png) no-repeat bottom center;
    background-size: 121px auto;
}


/* n 2是从第二个开始,-n 2是前两个 */

.nav-items:nth-child(n 2) {
    border-left: 1px solid #fff;
}

.nav-common:nth-child(1) {
    background: -webkit-linear-gradient(left, #fa5a55, #fa994d);
}

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

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

.subnav-entry {
    display: flex;
    border-radius: 8px;
    background-color: #fff;
    margin: 0 4px;
    /* 强制换行 */
    flex-wrap: wrap;
    padding: 5px 0;
}

.subnav-entry li {
    /* 里面的子盒子可以写%,相对于父级来说 */
    flex: 20%;
}

.subnav-entry a {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-shadow: 1px 1px rgb(0, 0, 0, .2);
}

.subnav-entry-icon {
    width: 28px;
    height: 28px;
    margin-top: 4px;
    background: url(../images/subnav-bg.png) no-repeat;
    background-size: 28px auto;
}

.sales-box {
    border-top: 1px solid #bbb;
    background-color: #fff;
    margin: 4px;
}

.sales-hd {
    position: relative;
    height: 44px;
    border-bottom: 1px solid #ccc;
}


/* SEO优化,此处其实是一张图片,但是出于优化,增加权重,仍然输入文字,然后用缩进 溢出隐藏来隐蔽文字,只显示图片 */

.sales-hd h2 {
    position: relative;
    text-indent: -999px;
    overflow: hidden;
}

.sales-hd h2::after {
    position: absolute;
    top: 8px;
    left: 20px;
    content: "";
    width: 79px;
    height: 15px;
    background: url(../images/hot.png) no-repeat 0 -20px;
    background-size: 79px auto;
}

.sales-hd a {
    position: absolute;
    right: 5px;
    top: 0;
    background: -webkit-linear-gradient(left, #ff506c, #ff6bc6);
    border-radius: 15px;
    padding: 3px 20px 3px 10px;
    color: #fff;
}

.sales-hd a::after {
    content: "";
    position: absolute;
    top: 9px;
    right: 9px;
    width: 7px;
    height: 7px;
    border-top: 2px solid #fff;
    border-right: 2px solid #fff;
    transform: rotate(45deg);
}

.row {
    display: flex;
}

.row a {
    flex: 1;
    border-bottom: 1px solid #eee;
}

.row a:nth-child(1) {
    border-right: 1px solid #eee;
}

.row a img {
    width: 100%;
}
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfibeah
系列文章
更多 icon
同类精品
更多 icon
继续加载