Those icons on the Web page

Source: Internet
Author: User

In the page of an HTML structure, the most commonly used icons are tags and css background-image . This is a label that is added for the display of images, suitable for large-sized images, strong image information, not part of the range of page categories (in Web design, the logo and the picture are two concepts: the logo can be evil to some extent, the effect of the trimming point able, there is no amount of information, but the picture is different, The picture is also a piece of information that you want to show to the user); Therefore, it is not reasonable to rely on the able of the target, because it is not the kind of thing to do, but also unfriendly to search engines.

Here's how to add a able to a web page by adding a trim point to the purpose of the logo.

Mode one: CSS for the sex background-image

Mainly used to set the background image of the class tag background-image , the general use of the following form:

.selector {     background-image:url( ‘/* 要顯示的圖片網址 */‘ );     background-repeat:no-repeat;     background-color: /* 背景顏色 */;}

This way does not put the information of the picture in the HTML structure, but through the CSS to protect the management; The biggest drawback of the way is that if there are a lot of similar icons in a page, then every visit to the user's client has to add a lot of HTTP requests to the able.

Of course, the best way to avoid unnecessary HTTP requests is to notch Minatomachi River multiple small icons into a large picture.

Way two: Reliance background-positionThe actual sprite map

Combine multiple small icons into a large picture, and the page elements are only selected as part of the display, so a bunch of small-picture-crafted large images are generally called Sprite images (sprites, Sprite, etc.).

In addition to the use of CSS, it is also used background-image to background-position locate the position of the large image of the small and medium-sized coordinates, and in general, to specify the long and wide information of the small graphic, that is, width and the height property. The general form of use is as follows:

.selector {    background-image: url(/* 要顯示的圖片網址 */);    background-repeat: no-repeat;    background-position: 0 -63px;    height: 10px;    width: 20px;}

The sprite avoids multiple HTTP requests, but the difficulty is that the creation of the sprite is a very tedious thing, and each update will need to re-map the sprite.

It is important to note that the position of the small icon in the sprite is written into the CSS background-position property.

The tedious of the sprite is generated by hand, but the technique of the self-generation of the sprite is also ripe, typically spriting with compass and glue.

If your CSS framework is based on Compass (SASS), the merging of sprite images is not something to consume, and if not, the use of glue will also allow you to detach from the non-programmed work of folding totem images.

Compass can be used directly when using a sprite map, and when it @include icon-sprite(‘/* 小圖標路徑 */‘) is finally translated into a CSS file, it also generates an adaptive sprite diagram, so you don't have to worry about a sit-down relationship; even if you want to switch to a graphic, you can just re-edit the title.

The use of glue is even more powerful, not only can generate CSS can also generate SCSS, and even the bottom layer you can generate a series of hash maps by their own hands to handle the use of the sprite logically album, the picture of the picture in the picture is a hash table, Completely free to customize.

Finally, the Notch Minatomachi River of the sprite has a problem with the God: so many small graphics, some pages in use and some pages do not have that how to do the Notch Minatomachi River Sprite map?

All the icons are notch Minatomachi River into a big picture? Not necessary, because some of the icons are not used in this page to procured what to spell together? In general, the Notch Minatomachi River logically of sprite images are as follows:

    • Page: Notch Minatomachi River's sprite diagram involves a small map only on a certain type of page (module use).
    • Type: The same type of icon Notch Minatomachi River in a sprite.
Method Three: Picture digital BASE64

The sprite map is one of the best solutions to use the able page of the graphic, close to perfection, but there is one problem that needs to be resolved:

The re-repeatability of the logo is unfriendly, that is, not very compatible background-repeat (usually set as no-repeat );

A typical example of a pentagram, if there are five stars to represent 100%, but to represent 80%, it must depend on repeat and width:80% .

There is also the use of the Electronic business site new , hot such as marketing tips small logo. These are miniature, and they need to be out of time, and it's always a awkward twist in a sprite.

In addition, the use of CSS sprite graphics to rely on external graphics, if the picture information directly in the CSS file. Images in the BASE64 format can be embedded in a CSS file as a string.

As a result, you can use a CSS file to copy the CSS file directly, no need to consider the external dependent graphics.

The BASE64 and encoding algorithms are also very easy, such as https://docs.python.org/2/library/base64.html. The compass is used directly by the base code @include inline-image(/* 圖標路徑 */) , and it is simple to create a sprite diagram as mentioned earlier.

In summary, the above-mentioned re-evaluation of the star and the electronic commercial site of the use of the new hot Small logo can be used in BASE64 format. Unfortunately, at the low end of the browser (IE6) is not supported by this method.

Mode four: The target is also the character Webfont

The previously mentioned map is a map, and the mobile screen is a 1080-megapixel browser, which makes it easy to saw teeth in high-resolution situations. If you use svg vector graphics, you can't do the sprite process.

It webfont is a way to use the image as a character (and to some extent it can also be interpreted as a vector-oriented sprite); Convert a series of vector icons into vector set files (such as woff formats) and use them as normal characters.

Not all browsers are supported by the current pain webfont , even if it supports the use of plain, flat graphics, and the browser's passing of the word to the text will cause the graphic to be distorted.

If the design of a Web site is purely color-adjusted, flat, then the use of a great range webfont is a good choice.

Way Five: CSS3 yourself

There are many pleasing features on CSS3, such as the property transorm tranition values of this change and passing, which are particularly effective when designing the background image of an element, and then setting up some CSS animations will result in interactive effects that are not available through the images.

This functionality is now only limited to limitations the background of the page element.

Another scenario is border to draw some set shapes in a way that uses the values of the Dependencies hack .

such as the drawing of triangles, in general, the most compatible CSS source code is as follows:

.triangle {    position: absolute;    top: 11px;    right: 7px; /* 絕對定位 */    width: 0;    height: 0;    font-size: 0;    border: 4px dashed transparent;    border-top: 4px solid #2bb8aa;    *display: none;}

Of course, there's always someone who likes to use CSS to draw graphics that are used to display images, and it's a job that consumes energy and does not necessarily work. Why do you want to make that simple work complicated? CSS is actually used to point able elements, rather than use to draw graphics.

Finally, the use of most of the site's graphics is done using the five methods mentioned above.

The strange thing about the Internet station 三角形 :

  • Solid triangles
  • caret [i.e. "^"]

These two icons are generally related to navigation (such as the top navigation), and the direction of the target will be reversed (it will blended the effect of some anti-rotation animation).

Those icons on the Web page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.