Home > Web Front-end > H5 Tutorial > body text

How to make various lists on H5 mobile terminal (6)

黄舟
Release: 2017-03-10 16:44:53
Original
1596 people have browsed it

How to make various lists on H5 mobile terminal (6)

If you saw this article first, it is recommended that you go to the above one first Link, take a look at the corresponding content, so that the context is coherent and it is easier to understand the content of this article.

In the first two chapters, we talked about a two-column layout of graphic and text lists. But the facts Above, the two-column layout of the image and text list is relatively simple. In this chapter, we will go one step further to challenge the difficulty. Implement a relatively complex layout method.

And, in order to be compatible with Android 4.4 Below, as well as some stupid domestic mobile browsers. In practice, we will give up the latest attributes such as calc\vh\vw and css3. Only use relatively simple parameters to achieve this Layout.

Complex graphics and text mixed list

This part is relatively complicated, but it is very common. Let’s take a look at the final rendering first.

How to make various lists on H5 mobile terminal (6)

As shown in the picture above, this should be regarded as a relatively complicated list of pictures and texts. I don’t know what kind of DOM framework you will build when you see this layout.

I am Think about it this way. In order for the backend to output conveniently, these six products must have a unified format. Therefore, my HTML code is as follows:

htmlcode

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>list 4</title><link rel="stylesheet" href="../style/style.css">
</head>
<body>
<p class="list_4">
    <ul>
        <li>
            <a href="goods/goods.html">
                <!-- 只有第一个有这个热售,其他的木有!~ -->
                <i class="goods_words">热售</i>
                <h3 class="goods_title">苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img src="../image/goods.jpg" alt="苹果iPhone6s" class="goods_photo">
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 class="goods_title">苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img src="../image/goods.jpg" alt="苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s" class="goods_photo">
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 class="goods_title">苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img src="../image/goods.jpg" alt="苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s" class="goods_photo">
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 class="goods_title">苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img src="../image/goods.jpg" alt="苹果iPhone6s" class="goods_photo">
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 class="goods_title">苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img src="../image/goods.jpg" alt="苹果iPhone6s" class="goods_photo">
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 class="goods_title">苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img src="../image/goods.jpg" alt="苹果iPhone6s" class="goods_photo">
            </a>
        </li>
    </ul></p></body></html>
Copy after login

You can see it in this In the HTML structure, I did not add different classes to li. In fact, when the backend outputs, different classes can be output. But this makes things complicated. Therefore, here, we only output Pure code. By the way, review my previous blog post "Detailed Discussion of the nth-child Selector of CSS3".

SASS Code

.list_4 {
    margin-top: 0.8rem;background:#fff;border-top: 1px solid #ddd;
    ul {@extend .cf;}
    li {
        background:#fff;outline: 1px solid #ddd;
        &:nth-child(-n+3) {
            width: 50%;height: 0;position: relative;
            a {display: block;position: absolute;left: 0;top: 0;height: 0;width: 100%;}
            .goods_photo {display: block;position: absolute;right:0.5rem;}
            .goods_title,.goods_info,.goods_price {z-index: 2;width: 60%;}
        }
        &:nth-child(1) {
            float: left;padding-bottom: 55%;
            a {padding-bottom: 110%;}
            .goods_photo {width: 50%;bottom: 5%;}
            .goods_title,.goods_info,.goods_price,.goods_words {margin-left: 1.6rem;}
            .goods_words {margin-top: 1.6rem;}
        }
        &:nth-child(n+2):nth-child(-n+3) {
            float: right;padding-bottom: 27.5%;
            a {padding-bottom: 55%;}
            .goods_photo {height: 70%;top: 15%;}
            .goods_title,.goods_info,.goods_price,.goods_words {margin-left: 1.2rem;}
            .goods_title {margin-top: 1.6rem;}
        }
        &:nth-child(n+4) {
            width: 33.3%;float: left;
            a {display: block;padding: 1rem;}
            .goods_photo {width: 70%;max-width: 15rem;margin: 0.5rem auto 0;display: block;}
        }
    }
}

// 全站范围内用到的图文基本样式
.goods_words {
    display:inline-block;
    padding:0.3rem 0.5rem;border-radius: 0.3rem;background:#f60;color:#fff;font-size: 1.2rem;margin-bottom: 0.5rem;
}
.goods_title,.goods_price,.goods_info {
    display: block;position: relative;
    @include ts(); // 引用文字描白边代码片
    @include online(1.8rem); // 引用文字超出一行省略号代码片
}
.goods_title {color:#000;font-size: 1.2rem;}
.goods_info {color:#999;font-size: 1.2rem;}
.goods_price {color:#f60;font-size: 1.5rem;font-weight: bold;}
Copy after login

In my previous blog post "Pure CSS In "Achieving Common Layouts on Mobile Terminals - The Secret of Linking Height and Width", I explained how to implement this layout. After the publication of that article, someone asked me, how do you arrange the content inside when you lay it out like this? I said to use positioning layout, but he still didn't understand. I don't know if he understood it after reading this article.

What the specific code means, I won't explain it in detail here. I read the analysis myself. Right. The key point is the use of nth-child. You can refer to my blog post above to understand what each of my selectors means. As well as positioning layout, etc.

Summary

The focus of this chapter is

  1. How CSS implements the height and width hooks of elements.

  2. Positioning layout is quite important

  3. nth-child It is really a very powerful CSS selector. How to use it in specific projects.

emphasize:
(1.) Android 4.4 or below and some domestic mobile browsers do not support the latest CSS attributes such as clac\ vw \ vh. Therefore, the method in this article It is solved using techniques in traditional CSS.
(2.) In this series of articles, I plan to explain some of my experiences and insights on the mobile terminal step by step. Some people exclaimed after reading the first chapter, this is too simple. I would like to ask a question, almost any programming book It started from hello world. Isn’t it all very simple?

The above is the detailed content of How to make various lists on H5 mobile terminal (6). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!