移动端HTML开发(模仿京东移动端)

     

制作过程中问题总结:

1、对于body特殊设置解释

body {
    width: 100%;
    margin: 0 auto;
    min-width: 320px;
    max-width: 640px;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    color: #666;
    line-height: 1.5;
    background-color: #ccc;
    height: 2000px;
}

把整个body的宽度设置为百分比方式以适应移动端流式布局,max\min-width去规定屏幕最大放大尺度,font-fmaily考虑到兼容性问题-apple-system适应iOS端,我们在开发时设置height便于后期开发

2、对于图片水平居中设定,在父元素中统一设定为text-align=center;line-height=盒子大小

具体解决方法链接观看:

(25条消息) 垂直居中、水平居中、移动盒子_小尘的一天的博客-CSDN博客

/* 图片植入成功对于水平居中方法为在父盒子里设置一系列参数 */

/* text-align: center;

    line-height: 45px; (水平居中法此特性有遗传性)*/

3、当多张图片在一起的时候会存在图片基线对齐的情况 ,解决方法利用

vertical-align=middle;

具体解决方法链接观看:(25条消息) CSS基线对齐的理解以及处理_cleverlovex的博客-CSDN博客_css基线对齐

在这里插入图片描述

 4、外边距合并问题解决方法:当子盒和父盒贴在一起我们给子盒子设定外边距会存在父盒子被合并在一起依旧贴一起且将父盒子的外边距加大(此原因也称外边距塌陷)

我们可以利用overflow:hidden很好解决此问题:

具体解决方法链接观看:

(25条消息) 关于overflow:hidden的作用(溢出隐藏、清除浮动、解决外边距塌陷等等)_星星之火M的博客-CSDN博客_overflow:hidden

5、流式布局搜索框技巧

搜索模块布局思路:划分三个模块但存在问题,我们开发的是移动端页面作为流式布局,我们需要去伸缩视口页面。要求我们在伸缩页面时左右两边位置不边,搜索框能自适应变化

1、我们有一个父盒子,利用定位左右两边(1号、3号盒子)固定死一个大小,然后在考虑中间的伸缩搜索框。准备一个标准流盒子(不指定宽度,其会默认与父元素一样宽),因为上面两个盒子是定位会脱离标准流不占位置,当我们的标准流加入,就会直接覆盖到盒子1号和3号盒子上面,我们可以考虑给个margin-left或者margin-right值让其存在于中间。简单总结左右给定位中间给margin-left和margin-right让它缩小到中间位置实现自适应效果

步骤如下:

.search-button {
    position: absolute;
    top: 0;
    left: 0;
    /* background-color: pink; */
    width: 40px;
    height: 44px;
}
.search-enter {
    position: absolute;
    top: 0;
    right: 0;
    /* background-color: pink; */
    width: 40px;
    height: 44px;
    color: #fff;
}
.search-find {
    position: relative;
    height: 30px;
    background-color: #fff;
    /* 这一步让搜索框进入到search区并且水平居中margin */
    margin: 0 50px;
    border-radius: 15px;
    margin-top: 10px;
}

6、给图片设置圆角边框办法

我们的图片是放在盒子里面的想要图片也能设置为圆角边框,我们可以对盒子设置溢出隐藏的效果overflow:hidden,就会对超出盒子的部分实现溢出隐藏的效果

代码如下

.three-pic {
    overflow: hidden;
    /* 这个下面我们对盒子设置了圆角边框属性,
    所以当我们对设置了如下属性毫无作用
    盒子只有那么大,我们设置的图片是不会删除的,只有利用overfloat:hideen
    对溢出盒子的部分实现隐藏才能达到预期效果 */
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

.three-pic ul li {
    float: left;
    width: 33.33%;
}

.three-pic ul li img {
    width: 100%;
}

7、流失布局盒子设置方法

/* 对于流式布局中插入图片的具体方法:

1、先画立100%的一个盒子然后区分开,

对图片宽度进行统一设定 */

.slide img {
    width: 100%;
}


.three-pic ul li {
    float: left;
    width: 33.33%;
}

 要求在.slide盒子里面放三个图我们采用设置3个33.33%

项目图:

项目页面代码展示

1、index.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">
    <title>Document</title>
    <link rel="stylesheet" href="../京东移动端开发/css/normalize.css">
    <link rel="stylesheet" href="../京东移动端开发/css/css.css">
</head>

<body>
    <!-- 顶部模块 -->
    <header class="p1">
        <ul>
            <li>
                <img src="../京东移动端开发/image/close.png" alt="">
            </li>
            <li>
                <img src="image/logo.png" alt="">
            </li>
            <li>打开京东App,购物更轻松,</li>
            <li><a href="https://www.jd.com/">立即打开</a> </li>
        </ul>
    </header>
    <!-- 搜索模块 -->
    <div class="search">
        <div class="search-button"></div>
        <div class="search-find">
            <ul>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="search-enter">登入</div>
    </div>
    <!-- 主题内容部分 -->
    <div class="main">
        <!-- 滑动图 -->
        <div class="slide">
            <img src="../京东移动端开发/upload/banner.dpg" alt="">
        </div>
    </div>
    <!-- 人物品牌日 -->
    <div class="three-pic">
        <ul>
            <li>
                <a href="#">
                    <img src="../京东移动端开发/upload/pic11.dpg" alt="">
                </a>
            </li>
            <li>
                <a href="#"> <img src="../京东移动端开发/upload/pic22.dpg" alt=""></a>

            </li>
            <li>
                <a href="#"><img src="../京东移动端开发/upload/pic33.dpg" alt=""></a>
            </li>
        </ul>
    </div>
    <!-- 加点10个导航区 -->
    <nav>
        <a href="#">
            <img src="../京东移动端开发/upload/nav1.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav2.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav3.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav1.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav2.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav2.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav3.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav1.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav2.webp" alt="">
            <span>京东超市</span>
        </a>
        <a href="#">
            <img src="../京东移动端开发/upload/nav3.webp" alt="">
            <span>京东超市</span>
        </a>
    </nav>
    <!-- 新闻快报 -->
    <div class="new">
        <a href="#">
            <img src="upload/new1.dpg" alt="">
        </a>
        <a href="#">
            <img src="upload/new2.dpg" alt="">
        </a>
        <a href="#">
            <img src="upload/new3.dpg" alt="">
        </a>

    </div>
    <!-- 为你推荐模块 -->
    <div class="recommend">
        <p>
            <span class="tuiJain111">为你推荐</span>
            <span>逛一逛</span>
        </p>
        <div>
            <img src="../京东移动端开发/image/图1.png" alt="">
        </div>
    </div>
    <!-- 推荐小模块价格公示区 -->




</body>

</html>

2、index.css

* {
    padding: 0px;
    margin: 0px;
    list-style-type: none;
}

img {
    /* 清除所有图片上下存在间隙的代码 */
    vertical-align: middle;
}

a {
    text-decoration: none;
    color: #666;
    -webkit-tap-highlight-color: none;
}

body {
    width: 100%;
    margin: 0 auto;
    min-width: 320px;
    max-width: 640px;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    color: #666;
    line-height: 1.5;
    background-color: #ccc;
    height: 2000px;
}


/* 顶部模块 */

.p1 {
    height: 45px;
}

.p1 ul li {
    float: left;
    height: 45px;
    background-color: #333;
    text-align: center;
    line-height: 45px;
}

.p1 ul li:nth-child(1) {
    text-align: center;
    line-height: 45px;
    width: 5%;
}


/* text-align: center;
    line-height: 45px; (水平居中法此特性有遗传性)*/


/* 图片植入成功对于水平居中方法为在父盒子里设置一系列参数 */

.p1 ul li:nth-child(1) img {
    width: 10px;
}

.p1 ul li:nth-child(2) {
    width: 10%;
}

.p1 ul li:nth-child(2) img {
    width: 30px;
    /* 图片在一起会存在基线对齐 */
    vertical-align: middle;
}

.p1 ul li:nth-child(3) {
    width: 57%;
}

.p1 ul li:nth-child(4) {
    width: 28%;
    background-color: #F63515;
}


/* 搜索模块 */


/* 外边距合并问题为什么利用overflow:hidden能解决 */

.search {
    position: fixed;
    /* 让底部图片覆盖上来 */
    width: 100%;
    height: 44px;
    min-width: 320px;
    max-width: 640px;
    overflow: hidden;
    line-height: 44px;
    text-align: center;
}


/* 为什么在一开始我们并没有对图片进行伸缩我们还能进行伸缩 */

.search-button {
    position: absolute;
    top: 0;
    left: 0;
    /* background-color: pink; */
    width: 40px;
    height: 44px;
}

.search-button::after {
    content: '';
    display: block;
    width: 20px;
    height: 18px;
    background: url(../image/s-btn.png) no-repeat;
    background-size: 20px 18px;
    margin: 16px 0px 0px 15px;
}

.search-enter {
    position: absolute;
    top: 0;
    right: 0;
    /* background-color: pink; */
    width: 40px;
    height: 44px;
    color: #fff;
}

.search-find {
    position: relative;
    height: 30px;
    background-color: #fff;
    /* 这一步让搜索框进入到search区并且水平居中margin */
    margin: 0 50px;
    border-radius: 15px;
    margin-top: 10px;
}

.search-find ul li:nth-child(1) {
    width: 20px;
    height: 15px;
    position: absolute;
    top: 8px;
    left: 13px;
    background: url(../image/jd.png) no-repeat;
    background-size: 20px 15px;
}

.search-find ul li:nth-child(1)::after {
    content: '';
    display: block;
    width: 1px;
    height: 15px;
    background-color: #ccc;
    position: absolute;
    top: 0px;
    right: -8px;
}


/* 放大镜图片制作!!! */

.search-find ul li:nth-child(2) {
    width: 18px;
    height: 15px;
    background-color: pink;
    position: absolute;
    top: 8px;
    left: 50px;
    background: url(../image/jd-sprites.png) -81px 0;
    background-size: 200px;
}


/* <!-- 主题内容部分 -->*/

.slide img {
    width: 100%;
}


/* 焦点图下人物拼接 */

.three-pic {
    overflow: hidden;
    /* 这个下面我们对盒子设置了圆角边框属性,
    所以当我们对设置了如下属性毫无作用
    盒子只有那么大,我们设置的图片是不会删除的,只有利用overfloat:hideen
    对溢出盒子的部分实现隐藏才能达到预期效果 */
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

.three-pic ul li {
    float: left;
    width: 33.33%;
}

.three-pic ul li img {
    width: 100%;
}

nav {
    margin-top: 5px;
}

nav a {
    text-align: center;
    float: left;
    width: 20%;
}

nav a img {
    width: 40px;
    margin: 10px 0;
}

nav a span {
    font-size: 12px;
    display: block;
}


/* <!-- 新闻快报 --> */


/* 对于流式布局中插入图片的具体方法:
1、先画立100%的一个盒子然后区分开,
为能插入图片尺寸一致采取对图片宽度进行统一设定 */

.new a {
    float: left;
}

.new a:nth-child(1) {
    width: 50%;
}

.new a:nth-child(2),
.new a:nth-child(3) {
    width: 25%;
    box-sizing: border-box;
    /* css3中有 box-sizing: border-box;用以在盒子内部压缩空间制作其他属性 */
    border-left: 1px solid #ccc;
}

.new a img {
    width: 100%;
}

.recommend {
    /* 清除以上带来的居中浮动 */
    clear: both;
    height: 207px;
}

.recommend p {
    position: relative;
}

.recommend p span:nth-child(1) {
    font-weight: 700;
    color: black;
    font-size: 18px;
    margin: 10px;
}

.tuiJain111::after {
    content: '';
    width: 1px;
    height: 12px;
    background-color: rgb(193, 193, 193);
    position: absolute;
    top: 10px;
    left: 89px;
}

.recommend p span:nth-child(2) {
    font-size: 12px;
    vertical-align: baseline;
}

.recommend div img {
    width: 100%;
    border-radius: 10px;
    height: 180px;
}


/* <!-- 推荐小模块 --> */

3、CSS初始化代码

/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */

/**
 * 1. Change the default font family in all browsers (opinionated).
 * 2. Correct the line height in all browsers.
 * 3. Prevent adjustments of font size after orientation changes in
 *    IE on Windows Phone and in iOS.
 */

/* Document
   ========================================================================== */

html {
  font-family: sans-serif; /* 1 */
  line-height: 1.15; /* 2 */
  -ms-text-size-adjust: 100%; /* 3 */
  -webkit-text-size-adjust: 100%; /* 3 */
}

/* Sections
   ========================================================================== */

/**
 * Remove the margin in all browsers (opinionated).
 */

body {
  margin: 0;
}

/**
 * Add the correct display in IE 9-.
 */

article,
aside,
footer,
header,
nav,
section {
  display: block;
}

/**
 * Correct the font size and margin on `h1` elements within `section` and
 * `article` contexts in Chrome, Firefox, and Safari.
 */

h1 {
  font-size: 2em;
  margin: 0.67em 0;
}

/* Grouping content
   ========================================================================== */

/**
 * Add the correct display in IE 9-.
 * 1. Add the correct display in IE.
 */

figcaption,
figure,
main { /* 1 */
  display: block;
}

/**
 * Add the correct margin in IE 8.
 */

figure {
  margin: 1em 40px;
}

/**
 * 1. Add the correct box sizing in Firefox.
 * 2. Show the overflow in Edge and IE.
 */

hr {
  box-sizing: content-box; /* 1 */
  height: 0; /* 1 */
  overflow: visible; /* 2 */
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

pre {
  font-family: monospace, monospace; /* 1 */
  font-size: 1em; /* 2 */
}

/* Text-level semantics
   ========================================================================== */

/**
 * 1. Remove the gray background on active links in IE 10.
 * 2. Remove gaps in links underline in iOS 8+ and Safari 8+.
 */

a {
  background-color: transparent; /* 1 */
  -webkit-text-decoration-skip: objects; /* 2 */
}

/**
 * Remove the outline on focused links when they are also active or hovered
 * in all browsers (opinionated).
 */

a:active,
a:hover {
  outline-width: 0;
}

/**
 * 1. Remove the bottom border in Firefox 39-.
 * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
 */

abbr[title] {
  border-bottom: none; /* 1 */
  text-decoration: underline; /* 2 */
  text-decoration: underline dotted; /* 2 */
}

/**
 * Prevent the duplicate application of `bolder` by the next rule in Safari 6.
 */

b,
strong {
  font-weight: inherit;
}

/**
 * Add the correct font weight in Chrome, Edge, and Safari.
 */

b,
strong {
  font-weight: bolder;
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

code,
kbd,
samp {
  font-family: monospace, monospace; /* 1 */
  font-size: 1em; /* 2 */
}

/**
 * Add the correct font style in Android 4.3-.
 */

dfn {
  font-style: italic;
}

/**
 * Add the correct background and color in IE 9-.
 */

mark {
  background-color: #ff0;
  color: #000;
}

/**
 * Add the correct font size in all browsers.
 */

small {
  font-size: 80%;
}

/**
 * Prevent `sub` and `sup` elements from affecting the line height in
 * all browsers.
 */

sub,
sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

sub {
  bottom: -0.25em;
}

sup {
  top: -0.5em;
}

/* Embedded content
   ========================================================================== */

/**
 * Add the correct display in IE 9-.
 */

audio,
video {
  display: inline-block;
}

/**
 * Add the correct display in iOS 4-7.
 */

audio:not([controls]) {
  display: none;
  height: 0;
}

/**
 * Remove the border on images inside links in IE 10-.
 */

img {
  border-style: none;
}

/**
 * Hide the overflow in IE.
 */

svg:not(:root) {
  overflow: hidden;
}

/* Forms
   ========================================================================== */

/**
 * 1. Change the font styles in all browsers (opinionated).
 * 2. Remove the margin in Firefox and Safari.
 */

button,
input,
optgroup,
select,
textarea {
  font-family: sans-serif; /* 1 */
  font-size: 100%; /* 1 */
  line-height: 1.15; /* 1 */
  margin: 0; /* 2 */
}

/**
 * Show the overflow in IE.
 * 1. Show the overflow in Edge.
 */

button,
input { /* 1 */
  overflow: visible;
}

/**
 * Remove the inheritance of text transform in Edge, Firefox, and IE.
 * 1. Remove the inheritance of text transform in Firefox.
 */

button,
select { /* 1 */
  text-transform: none;
}

/**
 * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video`
 *    controls in Android 4.
 * 2. Correct the inability to style clickable types in iOS and Safari.
 */

button,
html [type="button"], /* 1 */
[type="reset"],
[type="submit"] {
  -webkit-appearance: button; /* 2 */
}

/**
 * Remove the inner border and padding in Firefox.
 */

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
  border-style: none;
  padding: 0;
}

/**
 * Restore the focus styles unset by the previous rule.
 */

button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
  outline: 1px dotted ButtonText;
}

/**
 * Change the border, margin, and padding in all browsers (opinionated).
 */

fieldset {
  border: 1px solid #c0c0c0;
  margin: 0 2px;
  padding: 0.35em 0.625em 0.75em;
}

/**
 * 1. Correct the text wrapping in Edge and IE.
 * 2. Correct the color inheritance from `fieldset` elements in IE.
 * 3. Remove the padding so developers are not caught out when they zero out
 *    `fieldset` elements in all browsers.
 */

legend {
  box-sizing: border-box; /* 1 */
  color: inherit; /* 2 */
  display: table; /* 1 */
  max-width: 100%; /* 1 */
  padding: 0; /* 3 */
  white-space: normal; /* 1 */
}

/**
 * 1. Add the correct display in IE 9-.
 * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera.
 */

progress {
  display: inline-block; /* 1 */
  vertical-align: baseline; /* 2 */
}

/**
 * Remove the default vertical scrollbar in IE.
 */

textarea {
  overflow: auto;
}

/**
 * 1. Add the correct box sizing in IE 10-.
 * 2. Remove the padding in IE 10-.
 */

[type="checkbox"],
[type="radio"] {
  box-sizing: border-box; /* 1 */
  padding: 0; /* 2 */
}

/**
 * Correct the cursor style of increment and decrement buttons in Chrome.
 */

[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
  height: auto;
}

/**
 * 1. Correct the odd appearance in Chrome and Safari.
 * 2. Correct the outline style in Safari.
 */

[type="search"] {
  -webkit-appearance: textfield; /* 1 */
  outline-offset: -2px; /* 2 */
}

/**
 * Remove the inner padding and cancel buttons in Chrome and Safari on macOS.
 */

[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

/**
 * 1. Correct the inability to style clickable types in iOS and Safari.
 * 2. Change font properties to `inherit` in Safari.
 */

::-webkit-file-upload-button {
  -webkit-appearance: button; /* 1 */
  font: inherit; /* 2 */
}

/* Interactive
   ========================================================================== */

/*
 * Add the correct display in IE 9-.
 * 1. Add the correct display in Edge, IE, and Firefox.
 */

details, /* 1 */
menu {
  display: block;
}

/*
 * Add the correct display in all browsers.
 */

summary {
  display: list-item;
}

/* Scripting
   ========================================================================== */

/**
 * Add the correct display in IE 9-.
 */

canvas {
  display: inline-block;
}

/**
 * Add the correct display in IE.
 */

template {
  display: none;
}

/* Hidden
   ========================================================================== */

/**
 * Add the correct display in IE 10-.
 */

[hidden] {
  display: none;
}

  • 5
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值