Home Web Front-end HTML Tutorial DIV CSS layout page rendering speed faster writing method_html/css_WEB-ITnose

DIV CSS layout page rendering speed faster writing method_html/css_WEB-ITnose

Jun 24, 2016 pm 12:28 PM

1、*{} #zishu *{} 尽量避开

由于不同浏览器对HTML标签的解释有差异,所以最终的网页效果在不同的浏览器中可能是不一样的,为了消除这方面的风险,设计者通常会在CSS的一个始就把所有标签的默认属性全部去除,

以达到所有签标属性值都统一的效果。所以就有了*通配符。*会遍历所有的标签;

*{margin:0; padding:0}
如果这样写,页面中所有的标签的margin全是0;padding也是0;

#zishu *{margin:0; padding:0}
如果这样写,在id等于zishu下边的所有标签的margin全是0;padding也是0;

这样写的问题是:

遍历会消耗很多的时间,如果你的HTML代码写的不规范或是某一签标没有必合,这个时间可能还会更长;
很多的标签本来就没有这个属性或属性本身就是统一的,那么更给设置一次,也有时间的开消;
建议的的解决办法:

不要去使用生僻的标签,因为这些标签往往在不同浏览器中解释出来的效果不一样;所以你要尽可能的去使用那些常用的标签;
不要使用*;而是把你常用到的这些标签进行处理;例如:body,li,p,h1{margin:0; padding:0}
2、滤镜的一些东西不要去用

IE的一些滤镜在FIREFOX中不支持,往往写一些效果时你还是使用CSS HACK;而滤镜是一个非常毫资源的东西;特别是一些羽化、阴影和一个前透明的效果;

例如一个阴影效果:


test




建议的解决办法:

能不使用就不要使用,一方面兼容问题;很多效果只能在IE中使用;
就本例而言,如果非要这样在的效果,建议用图片作背景;(只说优化速度,实际应用还是可以小部分用,有人可能会说,用图片还多一个HTTP请求呢,呵呵……)
一个非常好的例子,就是在今年512大地震时,很多网站一夜之间全部变成了灰色,他们只用了一行CSS代码:

body{filter: gray;}

但,你会看会看到这些网页非常的慢,打开后你的CPU也会飙升,不夸张的说,如果你的电脑配置差,干死你也不为过。

3、一个页面上少用绝对定位

绝对定位(position:absolute )是网页布局中很常用到的,特别是作一些浮动效果时,也会让页面看起来非常的酷。但网页中如果使用过多的绝对定位,会让你的网页变得非常的慢,这一

点上边FIREFOX表现要比IE还要差。

例如:



  • 001

  • 001

  • 001

  • ……

建议的解决办法:

尽可能少用,这个少用的值是多少,也没有一个非常好的值来说明;还要看绝定定位这个标签里边的内容的多少;在这里我只能说,这样写会有性能问题,少用。
如果能用变通实现同样的效果,就用变通的办法
4、background 背景图片的平铺

有些网页的背景或页面中某块的背景通常要用到图片的平铺,平铺后就会有平铺次数的问题,如果是单次还好,如果是多次,就废了。

举个简单的例子:

例一:滚动一下你的页面,看速度怎么样?


例二:同样效果,再试一下这个!


Note: Test the two effects above. The worse your computer is, the more obvious it will be. If your computer configuration is very good, you can try changing the 8000px to 9000000px. If it still doesn’t work, change it to a larger one. Some, don’t scold me when you’re in trouble!

Suggested approach:

Pictures with few colors should be made into gif pictures;
The tiled pictures should be as large as possible. If it is a GIF picture with few colors, the picture should be larger. The size will not be much larger; the two examples above prove it very well. The first picture has very few pictures, and the second picture is larger; but the speed is very different

;
5. Inherit as many attributes as possible

As much as possible, let some attributes inherit from the parent instead of overwriting the parent;

A simple example:

< ;style>
a:link,a:visited{color:#0000FF}
a:hover,a:active{color:#FF0000}
#zishu a:link,#zishu a:visited{ font-weight:bold}
#zishu a:hover,#zishu a:active{ font-style: italic;}

test


6. The CSS path should not be too deep;

For example:

#zishu #info #tool #sidebar h2{ font-size:12px;}

7. Some abbreviations Just abbreviate;

For example:

#zishu{pading-top:10px; padding-right:50px; padding-left:50px; padding-bottom:4px;}

Change to:

#zishu{padding:10px 50px 4px 50px}

This has no effect on rendering speed; it’s just a few fewer characters;

8. Don’t leave it empty class or no class in the HTML code;

9. Application of float

My feeling is that if used improperly, there will be performance problems 100%, and it is also very large , but I really don’t know how to make an example; here I can only suggest that if you don’t understand how float works, it’s better to use it less.

I once killed IE because of this. I wrote an example, although it has nothing to do with it: The death of IE__ turns out to be related to CSS

10. Reasonable Layout

Why do you say this? Reasonable layout can change the writing method and rendering process of CSS

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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

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

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

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles