Changchun web design teaches you eight CSS layout skills

by zhidian520 on 2011-07-07 14:30:59

There are eight CSS layout tips in Changchun web design that everyone should know, and it is hoped that they will be helpful to all.

1. If in doubt, test immediately. When errors occur, simple checks of the original code can save a lot of headaches. W3C has validation tools available for both XHTML and CSS. Note that errors at the beginning of a file may cause more errors due to improper structure or other factors; we recommend fixing some of the most obvious errors first and then retesting, which may significantly reduce the number of errors.

2. Remember to clear appropriately when using float functions. Floats can be dangerous and may not produce the results you expect. If you encounter floating elements extending to the edge of the outer container or other abnormal situations, make sure your approach is correct. Refer to Eric Meyer's tutorial on the Complex Spiral Consulting website.

3. Use padding or border to avoid margin collapsing when borders overlap. You might be frustrated by unexpected spaces or need a little space but cannot get it. If you use margin, it is easy to have margin collapsing; Andy Budd explains possible solutions on his website.

4. Try to avoid specifying padding/border and height/width simultaneously for an element. The Windows version of IE often causes problems with width and height calculations. There are methods to solve this issue, but if the parent element needs specified height and width, it’s best to apply margin to child elements within the parent, or when child elements need specified height and width, apply padding to the parent element to achieve the desired effect.

5. Do not rely on min-width/min-height. The Windows version of IE does not support these two properties. However, under certain conditions, the Windows version of IE can achieve effects equivalent to min-width/min-height, so as long as some filtering functions are applied to IE, the desired result can be achieved.

6. If in doubt, reduce percentages first. Sometimes errors can cause 50% + 50% to equal 100.1%, causing issues with the webpage. In such cases, try changing these values to 49%, or even 49.9%.

7. Remember the "TRouBLed" writing method. The shorthand syntax for border, margin, and padding follows a specific order: top, right, bottom, left, moving clockwise from the top. So, margin: 0 1px 3px 5px; means no margin on the top, 1 pixel on the right, and so on. Remembering "TRouBLe" will help you remember the correct order.

8. For any value that is not zero, specify units. CSS requires you to specify units for each font, margin, etc., (the only exception being line-height). For more exciting content on Changchun web design, please visit the Changchun web design website.