Based on the hard work of our predecessors, we can find the best solution to replace float: left with inline-block.
Html code
The code is as follows: |
Copy code |
<Div class = "list"> <Ul> <Li> </li> <Li> </li> <Li> </li> <Li> </li> <Li> </li> <Li> </li> </Ul> </Div> |
Css code (from taobaoued)
The code is as follows: |
Copy code |
. List { Font-size: 0;/* all browsers */ * Word-spacing:-1px;/* IE6, 7 */ } . List ul li { Font-size: 12px; Letter-spacing: normal; Word-spacing: normal; Vertical-align: top; Display: inline-block; * Display: inline; * Zoom: 1; } @ Media screen and (-webkit-min-device-pixel-ratio: 0 ){ /* Letter-spacing in firefox may cause horizontal element displacement out of normal streams */ . List { Letter-spacing:-5px;/* Safari and other browsers with 0 font sizes are not supported. N is adjusted based on the parent font */ } }
|
The final effect drawing is perfectly compatible
The code is as follows: |
Copy code |
<! Doctype html> <Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/> <Meta name = "viewport" content = "width = device-width, initial-scale = 1.0"> <! -- [If lt ie 9]> <Script src = "http://html5shiv.googlecode.com/svn/trunk/html5.js"> </script> <! [Endif] --> <Script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script> <Style type = "text/css"> Li {list-style: none ;} Body {padding-bottom: 44px ;} . Fl {float: left ;} . Fr {float: right ;} . Header,. footer {background: # EDEDED ;} . Header {width: 100%; height: 32px; line-height: 32px; margin-bottom: 12px ;} . Footer {position: fixed; bottom: 0; left: 0; width: 100%; height: 32px; line-height: 32px; _ position: static; background: #000; opacity :. 6; filter: alpha (opacity = 60 );} . Footer a {color: # fff ;} . Footer a: hover {color: # FF6633 ;} . Header nav,. footer nav {width: 980px; margin: 0 auto ;} . Footer. hd {background: # 0099CC; color: # fff; height: 32px; padding: 0 10px; margin: 0 10px; font-weight: bold ;} . Footer span,. footer a {float: left ;} /* Css start */ . List { Font-size: 0;/* all browsers */ * Word-spacing:-1px;/* IE6, 7 */ Max-width: 820px; Margin: 0 auto; } . List ul {_ width: 840px; margin-left:-20px ;} . List ul li { Max-width: 400px; Height: 279px; margin-left: 20px; Margin-bottom: 20px; Font-size: 12px; Letter-spacing: normal; Word-spacing: normal; Vertical-align: top; Display: inline-block; * Display: inline; * Zoom: 1; } @ Media screen and (-webkit-min-device-pixel-ratio: 0 ){ /* Letter-spacing in firefox may cause horizontal element displacement out of normal streams */ . List { Letter-spacing:-5px;/* Safari and other browsers with 0 font sizes are not supported. N is adjusted based on the parent font */ } } /* Css end */ </Style> </Head> <Body> <Header class = "header"> <Nav> </Nav> </Header> <! -- Html start --> <Div class = "list"> <Ul> <Li> </li> <Li> </li> <Li> </li> <Li> </li> <Li> </li> <Li> </li> </Ul> </Div> </Body> </Html> |
Replacing float: left with inline-block is not a hack, but an improvement.
When using inline-block, you must note that when you replace text with the background in IE7 and IE6, a bug occurs. The solution is to use font-size: 0; line-height: 0; replace text-indent:-9999px;, bug