Table of Contents
推荐文章
Home Web Front-end CSS Tutorial Detailed explanation of zoom attribute

Detailed explanation of zoom attribute

Mar 01, 2021 pm 02:16 PM

The zoom attribute is an IE-specific attribute. In addition to setting or retrieving the zoom ratio of the object, it can also trigger IE's haslayout attribute, clear floats, clear margin overlaps, etc.

Detailed explanation of zoom attribute

The operating environment of this article: Windows 7 system, CSS3 version, Dell G3 computer.

Zoom attribute of css

zoom attribute is exclusive to IE. In addition to setting or retrieving the zoom ratio of the object, it also has haslayout that can trigger IE. Properties, clear floating, clear margin overlap and other functions. However, it is worth noting that the Firefox browser does not support the zoom attribute, but the zoom attribute can also be supported in the webkit kernel browser.

(1) Let’s take a look at the role of zoom in non-IE browsers: Look at the example below. I accessed it under Google Chrome. In this example, the role of zoom is to zoom in to the original 2 times (readers can try the zoom operation themselves)

1.zoom:1

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8" />  
<style>  
    div{  
        width: 100px;  
        height: 100px;  
        border: 3px solid red;   
        zoom: 1;  
}  
</style>  
    </head>  
    <body>  
        <div>hello</div>  
    </body>  
<html>
Copy after login

The result of the above code is as shown in the figure:

Detailed explanation of zoom attribute

[Recommended learning: CSS video tutorial]

2.zoom: 2 means zooming in to 2 times the original size:

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8" />  
<style>  
    div{  
        width: 100px;  
        height: 100px;  
        border: 3px solid red;   
        zoom: 2;  
}  
</style>  
    </head>  
    <body>  
        <div>hello</div>  
    </body>  
<html>
Copy after login

The screenshot of the result is as follows:

Detailed explanation of zoom attribute

Note: zoom appears to support zooming in or out in non-IE browsers, but since this attribute is a non-standard css attribute, zoom is generally not used in non-IE browsers. To achieve the scaling effect of div, now you need to zoom in or out directly using the transform attribute of css3.

(2) After looking at the performance of zoom in non-IE browsers, we should take a look at the role of this attribute in IE browsers.

How to use Zoom:

zoom : normal | number
Copy after login

normal: Default value. Use the actual size of the object

number : % | unsigned floating point real number. When the floating point real value is 1.0 or the percentage is 100%, it is equivalent to the normal value of this attribute. In vernacular explanation, it is zoom: the following number is the magnification multiple, which can be a numerical value or a percentage. For example: zoom:1, zoom:120%. This attribute only works in IE, so its actual purpose is rarely used. The most commonly used function is to clear floats, etc., such as:

.border{ 
border:1px solid #CCC; 
padding:2px; 
overflow:hidden; 
_zoom:1; 
}
Copy after login

_zoom is a CSS hack for IE6. Functional part. The IE6 browser will execute zoom:1 to indicate the zoom ratio of the object, but here

overflow:hidden; and _zoom:1; are used together to clear the internal floating of the border.

In the same way, you can also use the same method to clear the overlapping problem of margin attributes in IE browser: This brings up the second role of the zoom attribute in IE, that is,

Compatible with IE6, IE7, and IE8 browsers, you often encounter some problems. You can use zoom:1 to solve them. It has the following functions:

(2) Trigger the haslayout of the IE browser to solve the floating problem under IE. Margin overlap and other issues.

For example, this site uses DIV to display one row and two columns. HTML code:

<div class="h_mainbox">   
<h2 id="推荐文章">推荐文章</h2>   
<ul class="mainlist">   
<li><a href="#" style="color:#0000FF" target="_blank">CSS库吧</a></li>   
<li><a href="#" style="color:#0000FF" target="_blank">原创< /a></li>   
</ul>   
</div>
Copy after login

CSS code:

.h_mainbox { border:1px solid #dadada; padding:4px 15px; background:url(../mainbox_bg.gif) 0 1px repeat-x; margin-bottom:6px; overflow:hidden}   
.h_mainbox h2 { font-size:12px; height:30px; line-height:30px; border-bottom:1px solid #ccc; color:#555;}   
.h_mainbox h2 span { float:right; font-weight:normal;}   
.h_mainbox ul { padding:6px 0px; background:#fff;}   
.mainlist { overflow:auto; zoom:1;}   
.h_mainbox li { width:268px; float:left; height:24px; overflow:hidden; background:url(../icon3.gif) 0 6px no-repeat; padding:0px 5px 0px 18px; line-height:200%;}
Copy after login

.mainlist where zoom:1 can be IE6, IE7, and IE8 display normally.

(3) The following is a summary of the common functions of the zoom attribute in IE browsers. I hope it will be helpful when using this attribute in the future:

1. Check whether the label of the page is closed

Don’t underestimate this, maybe the CSS BUG problem that you haven’t solved for two days only stems from this. After all, page templates are usually nested by developers, and they can easily make such problems.

Quick tip: You can use Dreamweaver to open the file to check. Generally, if there are no closed tags, they will be highlighted with a yellow background.

 2. Style exclusion method

Some complex pages may load N external link CSS files, then delete the CSS files one by one, find the specific CSS files triggered by the BUG, ​​and narrow the scope of locking.

For the problematic CSS style file just locked, delete the specific style definitions line by line, locate the specific trigger style definition, and even the specific trigger style attributes.

 3. Module confirmation method

Sometimes we can also start from the HTML elements of the page. Delete different HTML modules in the page and find the HTML module that triggers the problem.

 4. Check whether floats are cleared

In fact, there are many CSS BUG problems caused by not clearing floats. It is necessary to develop a good habit of clearing floats. It is recommended to use the method of clearing floats without additional HTML tags (try to avoid using similar methods like overflow:hidden;zoom:1 to clear floats, which will be too restrictive).

5. Check whether haslayout is triggered under IE

Many complex CSS BUGs under IE are closely related to IE’s unique haslayout. Familiarity and understanding of haslayout will help you solve complex CSS bugs with less effort. It is recommended to read "On having layout" translated by old9 (if you can't cross the great GFW, you can read the repost on the blue)

Quick tip: If haslayout is triggered, IE's debugging tool IE Developer Toolbar The haslayout value will be displayed as -1 in the properties.

6. Border and background debugging method

So the name suggests is to set a conspicuous border or background (usually black or red) for the element for debugging. This method is one of the most commonly used methods for debugging CSS bugs, and it is still applicable to complex bugs. Affordable and environmentally friendly^^

The last thing I want to emphasize is that developing good writing habits, reducing extra tags, being as semantic as possible, and complying with standards can actually save us a lot of extra complex CSS BUGs, more When we do, we actually create trouble for ourselves.

That’s all I have to say for now. If there are any mistakes in the above, please give me some advice.

The above is the detailed content of Detailed explanation of zoom attribute. For more information, please follow other related articles on the PHP Chinese website!

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)

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

See all articles