Home Web Front-end HTML Tutorial DIV+CSS背景一张整图(css sprites)

DIV+CSS背景一张整图(css sprites)

Jun 06, 2017 am 10:59 AM

以前看到很多大型网站,整个网站的背景图片,是同一张图片,下载他的背景图片,看到一张图片上有很多小图标。

也就是国外很流行的css sprites,目前国内也有很多网站这样用。

这次在写CSS+DIV时,也这样写了个整站,感觉虽然做网站的整站慢,但在网站的占用资源上,的确省了不少。

  原理,一般网站的图片都是分开的,每个图片的调用都会占用一个IIS链接,而现在把所有图片放在一张图上时,所有图片都是一个图片,只要调用一次图片,就可以提供整个网页的图片用,这样只占一个IIS链接。

  在制作过程用,就是把所有的图片,都用背景来实现,比如一个小图标,就用这显示,把exp的样式设置一个背景,背景就是一个图片。

如:

 .exp
{
background-image: url(bg.gif);/*背景图片*/
background-repeat: no-repeat;/*不平铺*/
background-position: -300px -50px;/*设置背景图片在整个图的位置,在前面加个负号*/
width=25px;/*宽度*/
height=25px;/*高度*/
}
Copy after login

看到上面的吧,在设置背景时,会指定背景在图片上的位置,然后控制宽度和高度的大小,这样就显示了一个图标了,同样的方法,把网站所有的界面图片都以这样的方法显示,每个图上都是取大图中的一小部分。

每个小图标在大图片中的位置,可以在PS里用线查看。

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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to implement the custom table function of clicking to add data in dcat admin? How to implement the custom table function of clicking to add data in dcat admin? Apr 01, 2025 am 07:09 AM

How to implement the table function of custom click to add data in dcatadmin (laravel-admin) When using dcat...

The latest ranking list of virtual currency trading platform APP (inventory of top 10 virtual currency trading platforms) The latest ranking list of virtual currency trading platform APP (inventory of top 10 virtual currency trading platforms) Mar 04, 2025 pm 03:51 PM

This article lists the top ten leading cryptocurrency exchanges in the world, including OKX, Binance, Gate.io, Huobi, Kraken, Coinbase, KuCoin, Crypto.com, Bitfinex and Bitstamp. With their strong technical strength, rich product lines, strict compliance operations and innovative ecological construction, these exchanges have taken the lead in the global cryptocurrency market. The article will introduce their special functions, technical architecture, security measures, compliance qualifications and ecosystem construction respectively, providing reference for investors to choose a suitable trading platform.

Share the top ten official website addresses of the world's formal virtual currency trading software in 2025 Share the top ten official website addresses of the world's formal virtual currency trading software in 2025 Feb 15, 2025 pm 04:42 PM

With the development of the cryptocurrency market, formal virtual currency trading software has become the focus of investors' attention. In the fierce competition, some trading platforms stand out and provide safe and reliable services. According to industry research and comprehensive rankings, this article will list the top ten best virtual currency trading software in the world in 2025 and provide its official website address. These platforms have been strictly reviewed and are designed to provide users with excellent trading experience and investment guarantees.

Dynamic web page elements XPath and Class names change frequently. How to stably crawl the target a tag? Dynamic web page elements XPath and Class names change frequently. How to stably crawl the target a tag? Apr 01, 2025 pm 04:12 PM

Dynamic web element crawling problem: dealing with XPath and Class name changes, many crawler developers will encounter a difficult problem when crawling dynamic web pages: the goal...

How to share the same page on the PC and mobile side and handle cache issues? How to share the same page on the PC and mobile side and handle cache issues? Apr 01, 2025 pm 01:57 PM

How to share the same page on the PC and mobile side and handle cache issues? In the nginx php mysql environment built using the Baota background, how to make the PC side and...

From PHP to Go or Front-end? The suggestions and confusions of reality from experienced people From PHP to Go or Front-end? The suggestions and confusions of reality from experienced people Apr 01, 2025 pm 02:12 PM

Confusion and the cause of choosing from PHP to Go Recently, I accidentally learned about the salary of colleagues in other positions such as Android and Embedded C in the company, and found that they are more...

Ranking of virtual currency apps in the top ten exchanges in the currency circle Introduction to the list of 2025 currency trading platform apps Ranking of virtual currency apps in the top ten exchanges in the currency circle Introduction to the list of 2025 currency trading platform apps Jan 16, 2025 pm 06:39 PM

The top ten cryptocurrency exchange app rankings in 2025 are: Binance, Coinbase, OKX, Huobi Global, KuCoin, Kraken, Gate.io, Bitfinex, Poloniex and Bitstamp. They stand out with their low trading fees, wide range of crypto assets, advanced trading tools, focus on compliance, and user-friendly interfaces.

How to configure only allow access to index.php files in Nginx? How to configure only allow access to index.php files in Nginx? Apr 01, 2025 am 07:57 AM

The specific method of Nginx configuration only allows access to index.php. When using Nginx as a web server, sometimes we need to strictly control access, compared to...

See all articles