一直专注于PC网站的开发,不曾接触手机网站,于今日机缘巧合也是公司业务需要,并在之前学习过flex的布局,于是一并实践。碰到的问题还是很多的,主要是谈谈flex布局。
flex布局是css3里的内容,一种新的布局方式,也称之为 弹性布局,主要是为了取代 inline-bolck 和float 为总布局。当然,这两种布局还是有各自的优势的,毕竟存在就有他的理由。
历史进程是 box-->flexbox --> flex
由于是在谷歌调试,所以很理所当然的以为手机上的浏览器都是支持html5+css3的于是就有一段版本
1 display: flex; 2 justify-content: space-between; 3 align-items:center;
等等
在http://www.responsinator.com/ 等测试网站表现得挺满意的
拿到真机上测,无论苹果还是安卓布局全乱了。后来才知道在苹果上运行需要加前缀,因为浏览器都是-webkit-内核的,主要是因为还没实现标准化,都是私有属性,于是有了下面的写法
display: -webkit-flex; display: flex;-webkit-justify-content:space-between; justify-content: space-between; -webkit-align-items:center;align-items:center;
嗯,苹果上表现得相当不错,我用的4,除了屏幕小了点其他还是可以接受的。
拿到安卓上,呵呵,基本上公司的安卓机全军覆没,布局没有一点改变。测试机器一般都是近些时候的,最久的话也是1-2年前的机器。后来才知道原来是根本不是识别flex布局,只能用box(也就是很早之前的语法)来解决,就得到了如下的写法
1 .display_flex(){ 2 display: -webkit-box; 3 display: -webkit-flex; 4 display: flex; 5 } 6 .justify(){ 7 -webkit-justify-content: space-between; 8 -webkit-box-pack:justify; 9 justify-content: space-between; 10 }11 .justify(@ju)12 {13 -webkit-justify-content: @ju;14 -webkit-box-pack:@ju;15 justify-content: @ju; 16 }17 18 .align(@align)19 {20 -webkit-box-align:@align;21 -webkit-align-items: @align;22 align-items: @align; 23 }24 .flex-flow-column(){25 -webkit-box-orient:block-axis;26 -webkit-flex-flow: column nowrap; 27 flex-flow: column nowrap; 28 }29 .flex(@f){30 -webkit-box-flex:@f;31 -webkit-flex: @f; 32 flex: @f;33 }
注:这是less的写法(我学的不是很好)
不过中间有些遗憾新的flex里有一种叫做“超出自动换行”的功能,box里也有类似的属性,但是所有的浏览器都不支持,所以只能选择其他的布局(如前面提到的float)来代替。
总结:
flex的布局基本都是考虑内核,PC上不是很推荐,因为国内大都要兼容IE7-8,可以考虑在移动端使用(毕竟只有安卓和苹果)。总而言之这种布局还是挺不错的,有学习的必要,像他们说的html5+css3必是未来的主流方向。
如有更好的解决方案望请不吝赐教,谢谢。
引用的资料:
http://www.w3cplus.com/css3/using-flexbox.html (旧的box)
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html (新的flex)

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

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.

Dreamweaver Mac version
Visual web development tools
