search
HomeWeb Front-endHTML Tutorial手机端分类页面的效果图实现 - 林七七

啥都不说先上效果图吧。
看到效果图,我首先把页面分割为以下模块。
其中有几个要注意的点:
1、点击板块1中的"城市1"、"城市2"等会切换版块2中不同的div模块;
2、板块2中有不同的div模块,它们的布局都如板块2所示,但只显示一个div模块,其它模块隐藏;
3、点击某个div模块中leftBar的某一项,会在rightBar中显示相对应的rightBar模块,其它rightBar模块隐藏。
4、header要固定在页首。
5、页面布局用百分比来设定,调节width,以适应不同屏幕。
6、为适应不同手机屏幕,要在head标签内加上下面的一句代码:
     
 
现在解释下各部分实现的难点。
一、header部分
1、要固定页首,所以设置header为: position:fixed; top:0;
2、设置好header的高度,这到后面会有用的。
3、板块1中的"城市1"、"城市2",我直接用ul、li布局,
     设置li为 display: inline-block;
     为了实现分割线(如下图),我设置了li的padding和border-right,最后一个li设置 border-right:none; 即可。
4、header的背景图可用CSS3背景颜色渐变或图片解决,我偷了下懒,直接用图片。
 
二、leftBar部分
1、leftBar中的选项还是用ul、li来布局,至于leftBar我设的是float:left。
2、在完成leftBar过程中,我遇到两个问题:一是leftBar如何实现在rightBar中滚动内容时,leftBar保持固定在屏幕左端,且高度要延伸至屏幕底部。
   
先谈谈这个问题怎么解决吧,一开始直接设定了leftBar的高度为100%,但发现没什么用。在老大的提示下,先设置了html、body等leftBar的父元素的高度为100%,再设leftBar的高度为100%,就解决了高度问题。
 
为实现在rightBar中滚动内容时,leftBar保持固定在屏幕左端,我把leftBar设了position:fixed; 因为leftBar高度为屏幕高度的100%,所以导致leftBar过长,会无故出现竖直方向上的滚动条,为解决这个问题,我设了整个板块2为position:absolute; top:0 ;    再调节leftBar和rightBar的padding-top为header的高度即可。(板块2我也设了float:left; 所以它能包住leftBar&rightBar)
 
但是又出现了一个问题,leftBar有部分覆盖在header上,这时,我就设了header为position:relative; z-index:100; 让header悬浮在leftBar上即可。
 
问题二:怎么使leftBar上的选中选项的右边没有边?
一开始我是设了每个选项的border-right,但发现这条边是一直延伸至下方的。
在老大的提示下,我直接设了leftBar的border-right,对于选中项用margin-right:-1px;就可以把边挡住,但我用的是margin-left:1px;不知道为什么一开始margin-right起作用,后来又不起作用(希望有人能解释下,O(∩_∩)O谢谢)。
 
三、rightBar部分
rightBar部分比较简单,为了方便,我直接用table来布局,比较整齐,同样rightBar也要设padding-top为header的高度,其它应该没什么问题。
 
JS切换模块部分比较简单,我就省略不讲了。
如果有人想探讨交流或要源码,可以留言,O(∩_∩)O谢谢
如有不足,请帮我指出。

 

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
The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools