search
HomeWeb Front-endH5 TutorialHow to make various lists on H5 mobile terminal (6)

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 id="苹果iPhone-s">苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img class="goods_photo lazy"  src="/static/imghwm/default1.png"  data-src="../image/goods.jpg"   alt="苹果iPhone6s" >
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 id="苹果iPhone-s苹果iPhone-s苹果iPhone-s苹果iPhone-s">苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img class="goods_photo lazy"  src="/static/imghwm/default1.png"  data-src="../image/goods.jpg"   alt="苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s" >
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 id="苹果iPhone-s苹果iPhone-s苹果iPhone-s苹果iPhone-s">苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img class="goods_photo lazy"  src="/static/imghwm/default1.png"  data-src="../image/goods.jpg"   alt="苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s" >
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 id="苹果iPhone-s苹果iPhone-s苹果iPhone-s苹果iPhone-s">苹果iPhone6s苹果iPhone6s苹果iPhone6s苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img class="goods_photo lazy"  src="/static/imghwm/default1.png"  data-src="../image/goods.jpg"   alt="苹果iPhone6s" >
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 id="苹果iPhone-s">苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img class="goods_photo lazy"  src="/static/imghwm/default1.png"  data-src="../image/goods.jpg"   alt="苹果iPhone6s" >
            </a>
        </li>
        <li>
            <a href="goods/goods.html">
                <h3 id="苹果iPhone-s">苹果iPhone6s</h3>
                <p class="goods_info">A1700</p>
                <em class="goods_price">¥4679.00</em>
                <img class="goods_photo lazy"  src="/static/imghwm/default1.png"  data-src="../image/goods.jpg"   alt="苹果iPhone6s" >
            </a>
        </li>
    </ul></p></body></html>

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;}

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!

Statement
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
H5: Key Improvements in HTML5H5: Key Improvements in HTML5Apr 28, 2025 am 12:26 AM

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

HTML5: The Standard and its Impact on Web DevelopmentHTML5: The Standard and its Impact on Web DevelopmentApr 27, 2025 am 12:12 AM

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 Code Examples: Practical Applications and TutorialsH5 Code Examples: Practical Applications and TutorialsApr 25, 2025 am 12:10 AM

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

The Connection Between H5 and HTML5: Similarities and DifferencesThe Connection Between H5 and HTML5: Similarities and DifferencesApr 24, 2025 am 12:01 AM

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

The Building Blocks of H5 Code: Key Elements and Their PurposeThe Building Blocks of H5 Code: Key Elements and Their PurposeApr 23, 2025 am 12:09 AM

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

HTML5 and H5: Understanding the Common UsageHTML5 and H5: Understanding the Common UsageApr 22, 2025 am 12:01 AM

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5: The Building Blocks of the Modern Web (H5)HTML5: The Building Blocks of the Modern Web (H5)Apr 21, 2025 am 12:05 AM

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

H5 Code: Writing Clean and Efficient HTML5H5 Code: Writing Clean and Efficient HTML5Apr 20, 2025 am 12:06 AM

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function