国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end HTML Tutorial What is Css Hack_html/css_WEB-ITnose

What is Css Hack_html/css_WEB-ITnose

Jun 24, 2016 am 11:39 AM

What is a CSS hack? Since different browsers, such as Internet Explorer 6, Internet Explorer 7, Mozilla Firefox, etc., have different understandings of CSS parsing, the generated page effects will be different and the page effects we need will not be obtained.

At this time we need to write different CSS for different browsers so that it can be compatible with different browsers at the same time and get the page effects we want in different browsers.
This process of writing different CSS codes for different browsers is called CSS hack, also called writing CSS hack.
What is the principle of CSS Hack?
Because different browsers have different support and parsing results for CSS, and also because of the priority relationship in CSS. We can use this to write different CSS for different browsers.
For example, IE6 can recognize the underscore "_" and the asterisk "*", IE7 can recognize the asterisk "*", but cannot recognize the underscore "_", and Firefox cannot recognize both. Wait
The writing order is generally to write the CSS of browsers with strong recognition capabilities at the end. How to write is explained in more detail below.
 How to write CSS Hack
For example, to distinguish between IE6 and firefox browsers, you can write like this:
 
I see it as red in IE6 and green in firefox.
Explain:
The above css is in Firefox. It cannot recognize what the asterisked stuff behind it is, so it filters it out and ignores it. The result of the analysis is: div {background:green}, so of course the background of this div is green.
In IE6, both backgrounds can be recognized, and the result of its analysis is: div{background:green;background:red;}, so according to the priority level, the red at the back has a higher priority. , so of course the background color of this div is red.
CSS hack: Distinguish between IE6, IE7, firefox
Distinguish between different browsers, CSS hack writing:
Distinguish between IE6 and FF:
background:orange;*background:blue;
Distinguish between IE6 and FF IE7:
background:green !important; background:blue;
Difference between IE7 and FF:
background:orange; *background:green;
Difference between FF, IE7, IE6:
background: orange;*background:green;_background:blue;
background:orange;*background:green !important;*background:blue;
Note: IE can recognize *; standard browsers (such as FF) cannot recognize *;
IE6 can recognize *, but not !important,
IE7 can recognize * and also !important;
FF cannot recognize *, but can recognize !important;
IE6 IE7 FF " #demo {width:100px;} "For example;
 #demo {width:100px;} /*Executed by FIREFOX, IE6, IE7.*/
 * html #demo {width:120px;} /* Will be executed by IE6, the previous definition will be overwritten by the later one, so the width of #demo is 120px in IE6; */
 * html #demo {width:130px;} /*Will be executed by IE7*/
---------------
So in the end, the width of #demo is interpreted in the three browsers as:
FIREFOX:100px;
ie6:120px;
ie7:130px;

======================Gorgeous dividing line============ ==========

!important in CSS is a very important attribute and sometimes plays a very important role. 52CSS.com does not have much knowledge in this area. Let’s read the following article to get a comparative understanding of it. .
When I was writing some CSS code a few days ago, it was difficult for me again, because the damn IE6’s support for CSS is so poor. I haven’t noticed it before, because the things I make are basically based on IE, but The CSS I wrote for my blog this time needs to support more than one browser: IE. The unfortunate thing is that I installed Windows 7, which comes with IE8 browser. I thought there would be no problem, but when I open IE6, misalignment still occurs. , so I decided to see what was going on with IE6.
I wrapped all CSS blocks with borders, and found that the distance between two divs in IE is obviously wider than in other browsers. For example, if you write a div with a margin attribute of 20px, then in IE It seems to be 40px in IE, which is why the accuracy calculation is just right, but it is misaligned in IE.
Later I saw the !important attribute. This attribute is actually included in the CSS specification. As a result, IE6 did not support it. It was precisely because it did not support that many CSSers found a solution. Generally speaking, in CSS, if you write two same attributes in the same CSS block, then the bottom one is actually executed, for example:

view plaincopy to clipboardprint?
.home{
margin-left:20px;
margin-left:40px;
}
.home{
margin-left:20px;
margin-left:40px;
}

Then when executed, it is actually executed according to 40px. The appearance of !important is to allow users to set the priority of the executed statement. If you change the above statement to:

view plaincopy to clipboardprint?
.home{
margin-left:20px!important;
margin-left:40px;
}
.home{
margin-left:20px!important;
margin-left:40px;
}

Then in Firefox, Google browser and IE7 or above, it will be as follows 20px to execute, but under IE6 it still executes as 40px, because IE6 does not support the !important specification, we can follow this rule to meet the design needs of IE6, when we find that the display effects of IE6 and other browsers are different, then Just set two, add the !important tag to the upper one, and do not need to add the lower sentence, so that IE6 will execute it as follows.

====================== Gorgeous dividing line================== ====

It is a commonplace issue that CSS is compatible with various browsers. There are tutorials all over the Internet. The following content is not too novel and is purely a personal summary. I hope it can be helpful to beginners. Certain help.

1. CSS HACK
HACK concept:
Different browsers, such as Internet Explorer 6, Internet Explorer 7, Mozilla Firefox, etc., have different understandings of CSS parsing, so This will cause the generated page effects to be different, and we will not get the page effects we need. At this time, we need to write different CSS for different browsers so that it can be compatible with different browsers at the same time and get the page effects we want in different browsers. This process of writing different CSS codes for different browsers is called CSS hack,

HACK rules:

IE can recognize it*; standard browsers (such as FF) cannot recognize it* ;
IE6 can recognize *, but not !important,
IE7 can recognize *, but it can also recognize !important;
FF cannot recognize *, but can recognize !important;

IE6 IE7 FF
* √ √ ×
!important × √ √


Browser priority: FF

Example:

Take: " #demo {width:100px;} " as an example;

#demo {width:100px;}
* html #demo {width:120px;}
  * html #demo {width:130px;}
  ---------------
  So in the end, the width of #demo is The explanations of the three browsers are:

FIREFOX:100px;
ie6:120px;
ie7:130px;

The following two methods can solve almost all HACKs today.

1, !important

With IE7’s support for !important, the !important method is now only for IE6’s HACK. (Pay attention to the writing. Remember that the declaration position needs to be in advance.)


Note:
* html HACK for IE7 must ensure that there is the following statement at the top of the HTML:

2. Universal float closure

For the principle of clear float, please refer to [How To Clear Floats Without Structural Markup]
Add the following code to Global CSS and add class="clearfix" to the div that needs to be closed. It works every time.

3. Other compatibility tips


1. The
ul tag has a padding value by default in Mozilla, but in IE only margin has a value. So defining ul{margin:0;padding:0;} first can solve most problems. You can also use !important to solve

2. Centering problem.
1). Vertically centered. Set line-height to the same height as the current div, and then pass vertical-align: middle. (Be careful not to wrap the content .)
2). Horizontally centered. margin: 0 auto;(Of course not universal)
You can place any item within the body of the html, and the item will automatically obtain equal left and right boundary values ??to ensure Displayed in the center. However, this is still a problem in browsers before IE6 and will not be centered, so it must be modified as follows:
body {
text-align: center;
}
#content {
text-align: left;
width: 700px;
margin: 0 auto;
}
Setting the body will cause the main content to be centered, but even all the text will be centered. This is probably not the effect you want. For this reason, the div of #content also needs to specify a value: text-align: left

3. The BOX interpretation of IE5 and IE6 is inconsistent
div{width: under IE5 300px;margin:0 10px 0 10px;}
The width of the div will be interpreted as 300px-10px (right padding)-10px (left padding). The final width of the div is 280px,
while in IE6 and other browsers The top width is calculated as 300px 10px (right padding) 10px (left padding) = 320px.
At this time we can make the following modifications to div{width:300px!important;width:340px;margin:0 10px 0 10px}
I don’t quite understand what this is, I only know that both IE5 and firefox support it. IE6 does not support it. If anyone understands it, please let me know. Thanks! :)

4. Advance declaration of FORM tag and ul tag
These two tags will automatically have some margins in IE, while in FF the margin is 0, so if you want The display is consistent, so it is best to specify margin and padding in css. In response to the above two problems, I generally use this style ul first in my css, and form{margin:0;padding:0;} is defined, so You won’t have a headache later.

5.
cursor: pointer can display the cursor finger shape in IE FF at the same time, hand can only be displayed in IE

6.
If If the text is too long, change the long part into an ellipsis and display it: IE5, FF is invalid, but it can be hidden, IE6 is valid

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Hot Topics

PHP Tutorial
1502
276
Implementing Clickable Buttons Using the HTML button Element Implementing Clickable Buttons Using the HTML button Element Jul 07, 2025 am 02:31 AM

To use HTML button elements to achieve clickable buttons, you must first master its basic usage and common precautions. 1. Create buttons with tags and define behaviors through type attributes (such as button, submit, reset), which is submitted by default; 2. Add interactive functions through JavaScript, which can be written inline or bind event listeners through ID to improve maintenance; 3. Use CSS to customize styles, including background color, border, rounded corners and hover/active status effects to enhance user experience; 4. Pay attention to common problems: make sure that the disabled attribute is not enabled, JS events are correctly bound, layout occlusion, and use the help of developer tools to troubleshoot exceptions. Master this

Configuring Document Metadata Within the HTML head Element Configuring Document Metadata Within the HTML head Element Jul 09, 2025 am 02:30 AM

Metadata in HTMLhead is crucial for SEO, social sharing, and browser behavior. 1. Set the page title and description, use and keep it concise and unique; 2. Add OpenGraph and Twitter card information to optimize social sharing effects, pay attention to the image size and use debugging tools to test; 3. Define the character set and viewport settings to ensure multi-language support is adapted to the mobile terminal; 4. Optional tags such as author copyright, robots control and canonical prevent duplicate content should also be configured reasonably.

Best HTML tutorial for beginners in 2025 Best HTML tutorial for beginners in 2025 Jul 08, 2025 am 12:25 AM

TolearnHTMLin2025,chooseatutorialthatbalanceshands-onpracticewithmodernstandardsandintegratesCSSandJavaScriptbasics.1.Prioritizehands-onlearningwithstep-by-stepprojectslikebuildingapersonalprofileorbloglayout.2.EnsureitcoversmodernHTMLelementssuchas,

HTML for email templates tutorial HTML for email templates tutorial Jul 10, 2025 pm 02:01 PM

How to make HTML mail templates with good compatibility? First, you need to build a structure with tables to avoid using div flex or grid layout; secondly, all styles must be inlined and cannot rely on external CSS; then the picture should be added with alt description and use a public URL, and the buttons should be simulated with a table or td with background color; finally, you must test and adjust the details on multiple clients.

How to associate captions with images or media using the html figure and figcaption elements? How to associate captions with images or media using the html figure and figcaption elements? Jul 07, 2025 am 02:30 AM

Using HTML sums allows for intuitive and semantic clarity to add caption text to images or media. 1. Used to wrap independent media content, such as pictures, videos or code blocks; 2. It is placed as its explanatory text, and can be located above or below the media; 3. They not only improve the clarity of the page structure, but also enhance accessibility and SEO effect; 4. When using it, you should pay attention to avoid abuse, and apply to content that needs to be emphasized and accompanied by description, rather than ordinary decorative pictures; 5. The alt attribute that cannot be ignored, which is different from figcaption; 6. The figcaption is flexible and can be placed at the top or bottom of the figure as needed. Using these two tags correctly helps to build semantic and easy to understand web content.

How to handle forms submission in HTML without a server? How to handle forms submission in HTML without a server? Jul 09, 2025 am 01:14 AM

When there is no backend server, HTML form submission can still be processed through front-end technology or third-party services. Specific methods include: 1. Use JavaScript to intercept form submissions to achieve input verification and user feedback, but the data will not be persisted; 2. Use third-party serverless form services such as Formspree to collect data and provide email notification and redirection functions; 3. Use localStorage to store temporary client data, which is suitable for saving user preferences or managing single-page application status, but is not suitable for long-term storage of sensitive information.

What are the most commonly used global attributes in html? What are the most commonly used global attributes in html? Jul 10, 2025 am 10:58 AM

class, id, style, data-, and title are the most commonly used global attributes in HTML. class is used to specify one or more class names to facilitate style setting and JavaScript operations; id provides unique identifiers for elements, suitable for anchor jumps and JavaScript control; style allows for inline styles to be added, suitable for temporary debugging but not recommended for large-scale use; data-properties are used to store custom data, which is convenient for front-end and back-end interaction; title is used to add mouseover prompts, but its style and behavior are limited by the browser. Reasonable selection of these attributes can improve development efficiency and user experience.

Implementing Native Lazy Loading for Images in HTML Implementing Native Lazy Loading for Images in HTML Jul 12, 2025 am 12:48 AM

Native lazy loading is a built-in browser function that enables lazy loading of pictures by adding loading="lazy" attribute to the tag. 1. It does not require JavaScript or third-party libraries, and is used directly in HTML; 2. It is suitable for pictures that are not displayed on the first screen below the page, picture gallery scrolling add-ons and large picture resources; 3. It is not suitable for pictures with first screen or display:none; 4. When using it, a suitable placeholder should be set to avoid layout jitter; 5. It should optimize responsive image loading in combination with srcset and sizes attributes; 6. Compatibility issues need to be considered. Some old browsers do not support it. They can be used through feature detection and combined with JavaScript solutions.

See all articles