Some techniques of div design

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Recently in the garbage station, saw more and more rubbish station, with a few words to describe, completely only to make money, this point is true, the site may be seen under the IE6 is very intuitive, a IE7 under the fall, the station inside table set table. The whole world of the entire world of things has been back for a few years, I was doing the front desk project, I just want to say a few words, not to catch the mouse cat is a good cat. That is, you are making money at the same time, also give users a good sense, so perhaps remember your station will be more and more people, so as to get rid of Baidu and other search engines. At the same time also the Internet a better development trend.

Here are some tips for collecting and studying. Non-web designers do not look, otherwise, you will faint ... : }

CSS Compatibility tips

1, under the FF to the DIV set padding will cause the width and height increase, but IE will not. (Available!important solution)

2, center problem.

1. Vertically centered. Set the line-height to the same height as the current Div, and then pass the Vertical-align:middle. (Note that the content is not wrapped.)

2). Horizontally centered. margin:0 Auto;

3, if need to add a style to the content of a label, need to set display:block;

4, FF and IE on the BOX understanding of the difference between the 2px is also set for float div in IE under the margin doubling and so on.

5, the UL label under the FF default has List-style and padding. It is best to make a statement beforehand to avoid unnecessary trouble. (Common in navigation labels and content lists)

6, as an external wrappers div do not set dead height, preferably plus overflow:hidden. To achieve a high degree of adaptability.

7, about the hand-shaped cursor. Cursor:pointer. And hand only applies to IE.

1 CSS styles for Firefox IE6 IE7

Now most of them are using!important to hack, and for IE6 and Firefox tests to be shown,

But IE7 to!important can be correctly explained, will cause the page does not appear according to the request! Find a needle

To IE7 good hack way is to use "*+html", now with IE7 browsing, should have no problem.

Now write a CSS can do this:

#1 {color: #333;}/* Moz/*

* HTML #1 {color: #666}/* IE6 * *

*+html #1 {color: #999;}/* IE7/*

Then under Firefox font color display for #333,ie6 under the font color display for #666,ie7 under the font color display as #999.

2 centering problems in CSS layouts

The main style definitions are as follows:

body {text-align:center;}

#center {Margin-right:auto; Margin-left:auto; }

Description:

First, the parent element defines text-align:center, which means that the content within the parent element is centered;

But you can't center in Mozilla. The solution is to add "Margin-right:auto" when the child element definition is set; Margin-left:auto; ”

To be sure, if you want to use this method to make the entire page centered, it is recommended not to be nested in a div, you can split out multiple Div,

Just define the Margin-right:auto in each div that is removed; Margin-left:auto; .

3 box models different interpretations

#box {width:600px//for ie6.0-w\idth:500px;//for ff+ie6.0}

#box {width:600px!important//for ff width:600px//for ff+ie6.0 width/**/:500px;//for ie6.0-}

4 double distance from floating ie

#box {float:left; width:100px; margin:0 0 0 100px; In this case, IE will produce 200px distance display:inline; Make floating Ignore}

Let's go over the block,inline. Two elements, the block element is characterized by: always start on a new line, height, width, row height, margin can be controlled (blocks elements); Inline element is characterized by: and other elements on the same line,... Uncontrollable (inline element);

#box {display:block//can simulate an inline element as a block element display:inline//effect diplay:table the same row arrangement;

IE does not recognize the definition of min-, but in fact it treats the normal width and height as having min. That's a big problem, if you just use width and height,

In the normal browser, these two values will not change, if only with Min-width and min-height, ie below is not set width and height.

For example, to set the background picture, this width is more important. To solve this problem, you can do this:

#box {width:80px; height:35px;} Html>body #box {width:auto; height:auto; min-width:80px; min-height:35px;}

6 minimum width of the page

Min-width is a handy CSS command that specifies that the element should be minimal or less than a certain width, so that the layout will always be correct. But IE doesn't recognize this,

And it actually turns the width to the minimum. To make this command available on IE, you can put a

under the label and then specify a class for the DIV:

Then CSS is designed like this:

#container {min-width:600px width:expression (Document.body.clientWidth < 600?) "600px": "Auto");

The first min-width is normal, but the width of line 2nd uses JavaScript, which only IE recognizes, which makes your HTML document less formal. It actually achieves the minimum width through JavaScript's judgment.

7 Clear Floating

. hackbox{display:table;//Display the object as a table at the block element level} or. hackbox{Clear:both;

or add: After (Pseudo object), set in the object after the occurrence of content, usually with content with use, IE does not support this pseudo object, not IE browser support,

So it doesn't affect the Ie/win browser. This is the most troublesome ... #box: after{content: "."; display:block; height:0; clear:both; visibility:hidden;}

8 Div Floating IE text produces 3 pixel bugs

The left side of the object floating, the right side of the outer patch to locate the left margin, the right object within the text will be left with 3px spacing.

#box {float:left; width:800px;} #left {float:left; width:50%;} #right {width:50%;} *html #left {margin-right:-3px;//This sentence is the key}

HTML code

9 Property Selector (This is not compatible, is a hidden CSS bug)

p[id]{}div[id]{}

This is hidden from the IE6.0 and IE6.0 versions, and the FF and opera functions

There is a difference between the property selector and the child selector, and the scope of the child selector shrinks from the form, and the property selector is larger in scope, as in P[id], and all the IDs in the P tag are the same.

The question of IE hide-and-seek

When the div application is complex, there are some links in each column, div and so on this time is prone to hide and seek.

Some content does not appear when the mouse selects this area is found to be true on the page.

WORKAROUND: Use Line-height attribute for #layout or use fixed height and width for #layout. The page structure is as simple as possible.

11 Height Not suitable

Height is not adaptable when the height of the inner object changes when the outer height can not be automatically adjusted, especially when the inner object is used

Margin or paddign.

Cases:

Contents of the P object

CSS: #box {background-color: #eee;}

#box p {margin-top:20px;margin-bottom:20px; text-align:center;}

Workaround: Add 2 empty div object CSS code to the P object:. 1{height:0px;overflow:hidden;} Or add the border attribute to the Div.

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.