I believe that everyone is relatively familiar with the handling of common CSS BUGs, such as: IE6 Three Pixel Gap, IE5/6 Doubled Float-Margin Bug, etc. But we often encounter complex CSS BUG problems. The so-called "complex" essentially means that the triggering conditions are very complicated, and "BUG" does not necessarily mean that it is a browser BUG. For this kind of problem, the first thing we need to solve is how to locate the problem. Only by quickly locating the problem can we solve the problem better.
For quick positioning, my personal experience is generally as follows (it can basically locate more than 90% of the complex CSS BUG problems I encountered on Taobao):
1. Check whether the label of the page is closed.
Don’t underestimate this, it may cause trouble for you. The CSS BUG problem that has not been solved every day, but it 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 a 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. Being familiar with and understanding haslayout will get twice the result with half the effort in dealing with complex CSS bugs. 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, the properties in IE's debugging tool IE Developer Toolbar will be displayed haslayout value is -1.
6. The border and background debugging method,
as 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 to everyone is that developing good writing habits, reducing extra tags, trying to be semantic and complying with standards can actually save us a lot of extra complex CSS BUGs. More often than not, it is We create trouble for ourselves. I hope everyone will stay away from bugs and live a better and better life.