<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="css/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>蓝美网络 - DIV+CSS</title><link>http://www.itlanmei.com/blog/</link><description>蓝美科技最专业、最优惠、最好、最信的过的广州网站建设公司 - </description><generator>RainbowSoft Studio Z-Blog 1.8 Spirit Build 80722</generator><language>zh-CN</language><copyright>Copyright 广州蓝美计算机科技有限公司</copyright><pubDate>Thu, 09 Sep 2010 10:54:33 +0800</pubDate><item><title>最常用的12种CSS BUG解决方法与技巧</title><author>a@b.com (itlanmei)</author><link>http://www.itlanmei.com/blog/cat_6/dvicss22.html</link><pubDate>Tue, 04 Nov 2008 13:24:57 +0800</pubDate><guid>http://www.itlanmei.com/blog/cat_6/dvicss22.html</guid><description><![CDATA[<p>CSS&nbsp;bug是布局中最头疼的问题。我们需要兼顾各种浏览器，以期待获得一致的效果。非常遗憾的是各厂商之间的竞争导致很多问题的存在。而IE6与IE7在很多问题上也存在着很大的差别。在52CSS.com大量的技术文档中，也包含了这方面的内容。轻松的解决CSS&nbsp;bug是我们必须掌握的技能。现在整理出最常用的12种CSS&nbsp;BUG解决方法以及CSS&nbsp;BUG类的小技巧。希望对您的学习、工作有所帮助，如果您依然有疑问，欢迎您到52CSS.com查阅、搜索相关内容。</p><p><strong>一、&nbsp;针对浏览器的选择器</strong></p><p>这些选择器在你需要针对某款浏览器进行css设计时将非常有用。</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            　　IE6及其更低版本<br />            　　*&nbsp;html&nbsp;{}<br />            　　IE7及其更低版本<br />            　　*:first-child+html&nbsp;{}&nbsp;*&nbsp;html&nbsp;{}<br />            　　仅针对IE7<br />            　　*:first-child+html&nbsp;{}<br />            　　IE7和当代浏览器<br />            　　html&gt;body{}<br />            　　仅当代浏览器(IE7不适用)<br />            　　html&gt;/**/body{}<br />            　　Opera9及其更低版本<br />            　　html:first-child&nbsp;{}<br />            　　Safari<br />            　　html[xmlns*=&quot;&quot;]&nbsp;body:last-child&nbsp;{}<br />            &nbsp;</td>        </tr>    </tbody></table></p><p>要使用这些选择器,请将它们放在样式之前.&nbsp;例如:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            #content-box&nbsp;{&nbsp;<br />            width:&nbsp;300px;&nbsp;<br />            height:&nbsp;150px;&nbsp;<br />            }&nbsp;</td>        </tr>    </tbody></table></p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            *&nbsp;html&nbsp;#content-box&nbsp;{&nbsp;<br />            width:&nbsp;250px;&nbsp;<br />            }&nbsp;</td>        </tr>    </tbody></table></p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            当你想在一个浏览器里改变样式而不像在其他浏览器中改变时，这些选择器很有用。<br />            IE6以下</td>        </tr>    </tbody></table></p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            *html{}</td>        </tr>    </tbody></table></p><p>IE&nbsp;7&nbsp;以下</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            *:first-child+html&nbsp;{}&nbsp;*&nbsp;html&nbsp;{}</td>        </tr>    </tbody></table></p><p>只对IE&nbsp;7</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            *:first-child+html&nbsp;{}</td>        </tr>    </tbody></table></p><p>只对IE&nbsp;7&nbsp;和现代浏览器</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            html&gt;body&nbsp;{}</td>        </tr>    </tbody></table></p><p>&nbsp;</p><p>只对现代浏览器(非IE&nbsp;7)</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            html&gt;/**/body&nbsp;{}</td>        </tr>    </tbody></table></p><p>最新的Opera&nbsp;9以下版本</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            html:first-child&nbsp;{}</td>        </tr>    </tbody></table></p><p>Safari</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            html[xmlns*=&rdquo;&quot;]&nbsp;body:last-child&nbsp;{}</td>        </tr>    </tbody></table></p><p>要使用这些选择器，请在样式前写下这些代码。例如：</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            #content-box&nbsp;{&nbsp;<br />            width:&nbsp;300px;&nbsp;<br />            height:&nbsp;150px;&nbsp;<br />            }&nbsp;<br />            *&nbsp;html&nbsp;#content-box&nbsp;{&nbsp;<br />            width:&nbsp;250px;&nbsp;<br />            }&nbsp;<br />            /*&nbsp;重写上面的代码并且把宽度改为250PX&nbsp;<br />            在IE6以下版本中适用。&nbsp;*/</td>        </tr>    </tbody></table></p><p><strong>二、让IE6支持PNG透明</strong></p><p>一个IE6的Bug引起了大麻烦,&nbsp;他不支持透明的PNG图片。</p><p>你需要使用一个css滤镜</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            *html&nbsp;#image-style&nbsp;{&nbsp;<br />            background-image:&nbsp;none;&nbsp;<br />            filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=&quot;fil&nbsp;<br />            ename.png&quot;,&nbsp;sizingMethod=&quot;scale&quot;);&nbsp;<br />            }</td>        </tr>    </tbody></table></p><p><strong>三、移除超链接的虚线</strong></p><p>FireFox下,当你点击一个超链接时会在外围出现一个虚线轮廓.&nbsp;这很容易解决,&nbsp;只需要在标签样式中加入：</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            outline:none.<br />            a{&nbsp;<br />            outline:&nbsp;none;&nbsp;<br />            }</td>        </tr>    </tbody></table></p><p><strong>四、给行内元素定义宽度</strong> <br /><br />　　如果你给一个行内元素定义宽度,那么它只是在IE6下有效.&nbsp;所有的HTML元素要么是行内元素要么就好是块元素.&nbsp;行内元素包括：&lt;span&gt;,&nbsp;&lt;a&gt;,&nbsp;&lt;strong&gt;&nbsp;和&nbsp;&lt;em&gt;.&nbsp;块元素包括&lt;div&gt;,&nbsp;&lt;p&gt;,&nbsp;&lt;h1&gt;,&nbsp;&lt;form&gt;和&lt;li&gt;&nbsp;.&nbsp;你不能定义行内元素的宽度,&nbsp;为了解决这个问题你可以将行内元素转变为块元素。<br />span&nbsp;{&nbsp;width:&nbsp;150px;&nbsp;display:&nbsp;block&nbsp;}</p><p><strong>五、让固定宽度的页面居中</strong><br /><br />为了让页面在浏览器居中显示,&nbsp;需要相对定位外层div,&nbsp;然后把margin设置为auto.</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            #wrapper&nbsp;{&nbsp;<br />            margin:&nbsp;auto;&nbsp;<br />            position:&nbsp;relative;&nbsp;<br />            } <br />            &nbsp;</td>        </tr>    </tbody></table></p><p><strong>六、IE6双倍边距的bug</strong></p><p>给此对象加上display:inline即可解决问题。</p><p>IE6.0环境中双倍边距BUG。先看下面的CSS代码。</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            div&nbsp;{<br />            &nbsp;&nbsp;&nbsp;&nbsp;float:left;<br />            &nbsp;&nbsp;&nbsp;&nbsp;margin-left:10px;<br />            &nbsp;&nbsp;&nbsp;&nbsp;width:420px;<br />            &nbsp;&nbsp;&nbsp;&nbsp;height:150px;<br />            &nbsp;&nbsp;&nbsp;&nbsp;border:1px&nbsp;solid&nbsp;red<br />            &nbsp;&nbsp;&nbsp;&nbsp;}</td>        </tr>    </tbody></table></p><p>这样设置以后。本来左边距设置为10px，但IE6.0解释为20px，这是一个比较头疼的问题。但解决也非常简单。办法就是是加上display:inline。就搞定了。看下面的示例对比！</p><p><strong>双陪边距的效果：</strong></p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;<br />            &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />            &lt;head&gt;<br />            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />            &lt;title&gt;52css.com&lt;/title&gt;<br />            &lt;style type=&quot;text/css&quot;&gt;<br />            body {<br />            &nbsp;margin:0<br />            &nbsp;}<br />            div {<br />            &nbsp;float:left;<br />            &nbsp;margin-left:10px;<br />            &nbsp;width:420px;<br />            &nbsp;height:150px;<br />            &nbsp;border:1px solid red<br />            &nbsp;}<br />            &lt;/style&gt;<br />            &lt;/head&gt;<br />            &lt;body&gt;<br />            &lt;div&gt;<br />            Div+CSS XHTML XML 教程大全 - 52css.com&lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;&lt;/a&gt;<br />            &lt;/div&gt;<br />            &lt;/body&gt;<br />            &lt;/html&gt;</td>        </tr>    </tbody></table></p><p><strong>解决BUG以后的效果：</strong></p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;<br />            &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />            &lt;head&gt;<br />            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />            &lt;title&gt;52css.com&lt;/title&gt;<br />            &lt;style type=&quot;text/css&quot;&gt;<br />            body {<br />            &nbsp;margin:0<br />            &nbsp;}<br />            div {<br />            &nbsp;float:left;<br />            &nbsp;margin-left:10px;<br />            &nbsp;display:inline;<br />            &nbsp;width:420px;<br />            &nbsp;height:150px;<br />            &nbsp;border:1px solid red<br />            &nbsp;}<br />            &lt;/style&gt;<br />            &lt;/head&gt;<br />            &lt;body&gt;<br />            &lt;div&gt;<br />            Div+CSS XHTML XML 教程大全 - 52css.com&lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;Div+CSS XHTML XML 教程大全 &lt;br /&gt;&lt;/a&gt;<br />            &lt;/div&gt;<br />            &lt;/body&gt;<br />            &lt;/html&gt;</td>        </tr>    </tbody></table></p><p><strong>七、Box&nbsp;Model&nbsp;盒模型bug的一般解决办法</strong></p><p>&nbsp;我们定义一个最基本的层boxtest：</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            #boxtest{&nbsp;<br />            border:20px&nbsp;&nbsp;&nbsp;solid&nbsp;#60A179;<br />            padding:&nbsp;30px;<br />            background&nbsp;:&nbsp;&nbsp;#ffc;<br />            width&nbsp;:&nbsp;400px;<br />            }</td>        </tr>    </tbody></table></p><p>标准情况下，这个盒的宽度是:20+30+300+30+20=400px。</p><p>但是在IE5.0浏览器中，对盒模型的宽度解释有个bug，它认为300&nbsp;px是整个盒的总宽度，内容的宽度变成：300-20-30-20-30=200px。</p><p>为了弥补这个bug，采用一个技巧：即增加一个IE5不能解释的声音属性&quot;voice-family&quot;,读到这个定义时浏览器就不再继续阅读，认为宽就是400px，但而其他符合标准的浏览器会继续阅读，并执行第二个真实值300px。</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            #boxtest{<br />            border:20px&nbsp;solid&nbsp;#60A179;;&nbsp;<br />            padding:30px;<br />            background:&nbsp;#ffc;<br />            width&nbsp;:400px;<br />            voice-family&nbsp;:&nbsp;&nbsp;&nbsp;&quot;\&quot;}\&quot;&quot;;<br />            voice-family&nbsp;:inherit;<br />            width&nbsp;:&nbsp;&nbsp;300px;<br />            }</td>        </tr>    </tbody></table></p><p>同样，在Opera7.0以前的浏览器也有这样的解析bug。但我们并不需要使用伪值，有更简单的办法解决这个问题：&nbsp;html&gt;body&nbsp;.content&nbsp;{&nbsp;width&nbsp;:300;&nbsp;}</p><p><strong>八、两个层之间的3px间隙</strong></p><p>这个问题普遍的困扰着新手朋友，不知道如何是好，想不出办法进行解决。其实这就是传说中的&ldquo;IE&nbsp;3px&nbsp;bug&rdquo;。解决的办法也比较简单。请看下面的示例说明。</p><p><strong>IE中两个层之间的间隙（IE&nbsp;3px&nbsp;bug）</strong></p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;<br />            &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />            &lt;head&gt;<br />            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />            &lt;title&gt;52css.com&lt;/title&gt;<br />            &lt;style type=&quot;text/css&quot;&gt;<br />            &lt;!-- <br />            #left {<br />            &nbsp;float:left;<br />            &nbsp;width:200px;<br />            &nbsp;height:100px;<br />            &nbsp;background:#f00;<br />            &nbsp;}<br />            #right {<br />            &nbsp;width:200px;<br />            &nbsp;height:100px;<br />            &nbsp;background:#fc0;<br />            &nbsp;}<br />            --&gt;<br />            &lt;/style&gt;<br />            &lt;/head&gt;<br />            &lt;body&gt;<br />            &lt;div id=&quot;left&quot;&gt;52css.com&lt;/div&gt;<br />            &lt;div id=&quot;right&quot;&gt;52css.com&lt;/div&gt;<br />            &lt;/body&gt;<br />            &lt;/html&gt;</td>        </tr>    </tbody></table></p><p><strong>解决3px&nbsp;bug的方法之浮动法float</strong></p><p>此例中，我们给右边的层，应用float:left;浮动，即可解决IE&nbsp;3px&nbsp;bug。</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;<br />            &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />            &lt;head&gt;<br />            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />            &lt;title&gt;52css.com&lt;/title&gt;<br />            &lt;style type=&quot;text/css&quot;&gt;<br />            &lt;!-- <br />            #left {<br />            &nbsp;float:left;<br />            &nbsp;width:200px;<br />            &nbsp;height:100px;<br />            &nbsp;background:#f00;<br />            &nbsp;}<br />            #right {<br />            &nbsp;float:left;<br />            &nbsp;width:200px;<br />            &nbsp;height:100px;<br />            &nbsp;background:#fc0;<br />            &nbsp;}<br />            --&gt;<br />            &lt;/style&gt;<br />            &lt;/head&gt;<br />            &lt;body&gt;<br />            &lt;div id=&quot;left&quot;&gt;52css.com&lt;/div&gt;<br />            &lt;div id=&quot;right&quot;&gt;52css.com&lt;/div&gt;<br />            &lt;/body&gt;<br />            &lt;/html&gt;</td>        </tr>    </tbody></table></p><p><strong>解决3px&nbsp;bug的方法之障眼法</strong></p><p>此例中，我们给左边的层，应用margin-right:-3px;，同样可解决IE&nbsp;3px&nbsp;bug。</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;<br />            &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />            &lt;head&gt;<br />            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />            &lt;title&gt;52css.com&lt;/title&gt;<br />            &lt;style type=&quot;text/css&quot;&gt;<br />            &lt;!-- <br />            #left {<br />            &nbsp;float:left;<br />            &nbsp;width:200px;<br />            &nbsp;height:100px;<br />            &nbsp;margin-right:-3px;<br />            &nbsp;background:#f00;<br />            &nbsp;}<br />            #right {<br />            &nbsp;width:200px;<br />            &nbsp;height:100px;<br />            &nbsp;background:#fc0;<br />            &nbsp;}<br />            --&gt;<br />            &lt;/style&gt;<br />            &lt;/head&gt;<br />            &lt;body&gt;<br />            &lt;div id=&quot;left&quot;&gt;52css.com&lt;/div&gt;<br />            &lt;div id=&quot;right&quot;&gt;52css.com&lt;/div&gt;<br />            &lt;/body&gt;<br />            &lt;/html&gt;</td>        </tr>    </tbody></table></p><div class="content" id="textbody"><p>&nbsp;</p><p><strong>九、在IE中的HTML注释引起文字奇怪的复制</strong></p><p>当多个浮动的元素彼此跟随，中间加注释的时候，最后一个浮动元素内的文本偶尔会复制到最下面去。学名Duplicate&nbsp;Characters&nbsp;Bug</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br />            &lt;html xmlns=&quot;//www.w3.org/1999/xhtml&quot;&gt;<br />            &lt;head&gt;<br />            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;<br />            &lt;title&gt;多了一只猪&lt;/title&gt;<br />            &lt;/head&gt;<br />            &lt;body&gt;<br />            &lt;div style=&quot;width:400px&quot;&gt;<br />            &lt;div style=&quot;float:left&quot;&gt;&lt;/div&gt; <br />            &lt;!-- --&gt;<br />            &lt;div style=&quot;float:right;width:400px&quot;&gt;&darr;这就是多出来的那只猪&lt;/div&gt;<br />            &lt;/div&gt;<br />            &lt;/body&gt;<br />            &lt;/html&gt;</td>        </tr>    </tbody></table></p><p>可以通过以下的办法来解决：</p><p>1、不放置注释。最简单、最快捷的解决方法</p><p>2、注释不要放置于2个浮动的区块之间。</p><p>3、将文字区块包含在新的&lt;div&gt;&lt;/div&gt;之间，如：</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;div&nbsp;style=&quot;float:right;width:400px&quot;&gt;&lt;div&gt;&darr;这就是多出来的那只猪&lt;/div&gt;&lt;/div&gt;</td>        </tr>    </tbody></table></p><p>4、去除文字区块的固定宽度，与3有相似之处。</p><p>5、有的人在猪后加一个&lt;br&nbsp;/&gt;或者空格，但只是消除现象。</p><p>6、不要给浮动元素设置多宽度，使其不会到达包含元素的底部，或者对最后一个元素设置margin-right:&nbsp;-3px;或者更小。</p><p>7、注释可以这样写：</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;!--[if&nbsp;!IE]&gt;Put&nbsp;your&nbsp;commentary&nbsp;in&nbsp;here...&lt;![endif]--&gt;</td>        </tr>    </tbody></table></p><p><strong>十、图片替换技术</strong><br /><br />文字总比用图片做标题好一些.&nbsp;文字对屏幕阅读机和SEO都是非常友好的.<br /><br />&nbsp;</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            HTML:<br />            &lt;h1&gt;&lt;span&gt;Main&nbsp;heading&nbsp;one&lt;/span&gt;&lt;/h1&gt;<br />            CSS:<br />            h1&nbsp;{&nbsp;background:&nbsp;url(heading-image.gif)&nbsp;no-repeat;&nbsp;}&nbsp;<br />            h1&nbsp;span&nbsp;{&nbsp;<br />            position:absolute;&nbsp;<br />            text-indent:&nbsp;-5000px;&nbsp;<br />            }</td>        </tr>    </tbody></table></p><p>你可以看到我们对标题使用了标准的&lt;h1&gt;作为标签并且用css来将文本替换为图片.&nbsp;text-indent属性将文字推到了浏览器左边5000px处,&nbsp;这样对于浏览者来说就看不见了.</p><p>关掉css,然后看看头部会是什么！</p><p><strong>十一、&nbsp;最小宽度</strong></p><p>　　</p><p>IE6另外一个bug就是它不支持&nbsp;min-width&nbsp;属性.&nbsp;min-width又是相当有用的,&nbsp;特别是对于弹性模板来说,&nbsp;它们有一个100%的宽度,min-width&nbsp;可以告诉浏览器何时就不要再压缩宽度了。<br />除IE6以外所有的浏览器你只需要一个&nbsp;min-width:&nbsp;Xpx;&nbsp;例如:<br />&nbsp;</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            .container&nbsp;{&nbsp;<br />            min-width:300px;&nbsp;<br />            }<br />            &nbsp;</td>        </tr>    </tbody></table></p><p>为了让他在IE6下工作,&nbsp;我们需要一些额外的工作.&nbsp;开始的时候我们需要创建两个div,&nbsp;一个包含另一个:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &lt;div&nbsp;class=&quot;container&quot;&gt;&nbsp;<br />            &lt;div&nbsp;class=&quot;holder&quot;&gt;Content&lt;/div&gt;&nbsp;<br />            &lt;/div&gt;<br />            &nbsp;</td>        </tr>    </tbody></table></p><p>然后你需要定义外层div的min-width属性</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            &nbsp;.container&nbsp;{&nbsp;<br />            min-width:300px;&nbsp;<br />            }</td>        </tr>    </tbody></table></p><p>这时该是IE&nbsp;hack大显身手的时候了.&nbsp;你需要包含如下的代码:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><br />            *&nbsp;html&nbsp;.container&nbsp;{&nbsp;<br />            border-right:&nbsp;300px&nbsp;solid&nbsp;#FFF;&nbsp;<br />            }&nbsp;<br />            *&nbsp;html&nbsp;.holder&nbsp;{&nbsp;<br />            display:&nbsp;inline-block;&nbsp;<br />            position:&nbsp;relative;&nbsp;<br />            margin-right:&nbsp;-300px;&nbsp;<br />            }<br />            &nbsp;</td>        </tr>    </tbody></table></p><p>As&nbsp;the&nbsp;browser&nbsp;window&nbsp;is&nbsp;resized&nbsp;the&nbsp;outer&nbsp;div&nbsp;width&nbsp;reduces&nbsp;to&nbsp;suit&nbsp;until&nbsp;it&nbsp;shrinks&nbsp;to&nbsp;the&nbsp;border&nbsp;width,&nbsp;at&nbsp;which&nbsp;point&nbsp;it&nbsp;will&nbsp;not&nbsp;shrink&nbsp;any&nbsp;further.&nbsp;The&nbsp;holder&nbsp;div&nbsp;follows&nbsp;suit&nbsp;and&nbsp;also&nbsp;<br />stops&nbsp;<br />shrinking.&nbsp;The&nbsp;outer&nbsp;div&nbsp;border&nbsp;width&nbsp;becomes&nbsp;the&nbsp;minimum&nbsp;width&nbsp;of&nbsp;the&nbsp;inner&nbsp;div.</p><p><strong>十二、隐藏水平滚动条</strong></p><p>为了避免出现水平滚动条,&nbsp;在body里加入&nbsp;overflow-x:hidden&nbsp;。</p><p>当你决定使用一个比浏览器窗口大的图片或者flash时,&nbsp;这个技巧将非常有用。</p></div>]]></description><category>DIV+CSS</category><comments>http://www.itlanmei.com/blog/cat_6/dvicss22.html#comment</comments><wfw:comment>http://www.itlanmei.com/blog/</wfw:comment><wfw:commentRss>http://www.itlanmei.com/blog/feed.asp?cmt=17</wfw:commentRss><trackback:ping>http://www.itlanmei.com/blog/cmd.asp?act=tb&amp;id=17&amp;key=1f080682</trackback:ping></item><item><title>建站必备：23个符合Web标准的网站导航菜单</title><author>a@b.com (itlanmei)</author><link>http://www.itlanmei.com/blog/cat_6/16.html</link><pubDate>Tue, 04 Nov 2008 12:43:09 +0800</pubDate><guid>http://www.itlanmei.com/blog/cat_6/16.html</guid><description><![CDATA[<p>　　提供了23个使用 Xhtml + CSS 设计制作的、符合Web标准的网站导航菜单，可以为站长们设计网站提供非常不错的参考。推荐下载和学习。</p><p>　　在IE 5.0 或以上版本，Firefox 1.0或以上版本中测试通过。</p><p>　　<a href="http://www.letdig.com/dh/index.htm" target="_blank">点击这里在线预览23个导航菜单的效果</a>。</p><p>　　<a href="http://img2.pconline.com.cn/pconline/0703/20/983632_css-nav-menu.zip" target="_blank">点击这里打包下载导航菜单</a>。</p><p align="center"><img height="450" alt="" src="http://www.chinaz.com/Files/2007040617251334477.jpg" width="503" border="0" /></p>]]></description><category>DIV+CSS</category><comments>http://www.itlanmei.com/blog/cat_6/16.html#comment</comments><wfw:comment>http://www.itlanmei.com/blog/</wfw:comment><wfw:commentRss>http://www.itlanmei.com/blog/feed.asp?cmt=16</wfw:commentRss><trackback:ping>http://www.itlanmei.com/blog/cmd.asp?act=tb&amp;id=16&amp;key=f99e8422</trackback:ping></item><item><title>DIV+CSS设计实例：垂直树形下拉菜单</title><author>a@b.com (itlanmei)</author><link>http://www.itlanmei.com/blog/cat_6/div123.html</link><pubDate>Tue, 04 Nov 2008 12:39:27 +0800</pubDate><guid>http://www.itlanmei.com/blog/cat_6/div123.html</guid><description><![CDATA[<p><strong>第一步:建立菜单</strong></p><p>首先建立菜单架构非常重要,最好的方法是使用ul来建立各菜单内容的从主关系.很复杂么?其实只要一路写下去就OK了:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            &lt;ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;About&lt;/a&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;History&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Team&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Offices&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Services&lt;/a&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Web&nbsp;Design&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Internet&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marketing&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Hosting&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Domain&nbsp;Names&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Broadband&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;/li&gt; <br />            <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Contact&nbsp;Us&lt;/a&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;United&nbsp;Kingdom&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;France&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;USA&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;#&quot;&gt;Australia&lt;/a&gt;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;&nbsp; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&lt;/li&gt;&nbsp; <br />            &nbsp;&nbsp;&lt;/ul&gt;</td>        </tr>    </tbody></table></p><p><strong>第二步:视觉上的修饰</strong></p><p>上面所写的代码直接在浏览器下可以说非常的难看...所以我们先给他们加上点样式,不至于因为外表的问题弄的你没有兴趣继续做下去,呵呵</p><p>首先我们把烦人的点点去掉,并定义这个菜单的宽度:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            ul&nbsp;{ <br />            &nbsp;margin:&nbsp;0; <br />            &nbsp;padding:&nbsp;0; <br />            &nbsp;list-style:&nbsp;none; <br />            &nbsp;width:&nbsp;150px; <br />            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border-bottom:&nbsp;1px&nbsp;solid&nbsp;#ccc; <br />            &nbsp;}</td>        </tr>    </tbody></table></p><p>接下来,我们要定义里面内容部分,非常幸运,列表默认的排列就是垂直的,这与我们的要求相一致,定位方式我们应该设置为相对定位(relative)因为副菜单要在相对的位置上进行绝对定位:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            <font style="background-color: #ffffff" color="#ff0000">ul li {&nbsp; position: relative;&nbsp; }</font></td>        </tr>    </tbody></table></p><p>现在我们定义的就是副菜单的内容部分,使用left和top属性我们就可以让它们显示在主菜单内容的右边.display属性值为none所以在默认情况下是隐藏的:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            <font style="background-color: #ffffff" color="#ff0000">li ul {&nbsp; position: absolute;&nbsp; left: 149px;&nbsp; top: 0;&nbsp; display: none;&nbsp; }</font></td>        </tr>    </tbody></table></p><p>最后得修饰下里面的a元素:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            ul&nbsp;li&nbsp;a&nbsp;{ <br />            &nbsp;display:&nbsp;block; <br />            &nbsp;text-decoration:&nbsp;none; <br />            &nbsp;color:&nbsp;#777; <br />            &nbsp;background:&nbsp;#fff; <br />            &nbsp;padding:&nbsp;5px; <br />            &nbsp;border:&nbsp;1px&nbsp;solid&nbsp;#ccc; <br />            &nbsp;border-bottom:&nbsp;0; <br />            &nbsp;}</td>        </tr>    </tbody></table></p><p>但因为IE的显示BUG,所以得加上下面这段话进行修复:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            /*&nbsp;Fix&nbsp;IE.&nbsp;Hide&nbsp;from&nbsp;IE&nbsp;Mac&nbsp;\*/ <br />            *&nbsp;html&nbsp;ul&nbsp;li&nbsp;{&nbsp;float:&nbsp;left;&nbsp;} <br />            *&nbsp;html&nbsp;ul&nbsp;li&nbsp;a&nbsp;{&nbsp;height:&nbsp;1%;&nbsp;} <br />            /*&nbsp;End&nbsp;*/</td>        </tr>    </tbody></table></p><p><strong>第三部:让它运作起来</strong></p><p>我们需要在我们移动到主菜单上时显示副菜单内容:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            li:hover&nbsp;ul&nbsp;{&nbsp;display:&nbsp;block;&nbsp;}</td>        </tr>    </tbody></table><br />好了,你可以测试下代码了,1%人可能会兴奋地叫起来,呵呵遗憾的是就目前这些代码还不能够在IE上运做作出我们想要的结果.要让IE运作出一样的效果,我们得使用一段JS代码,不会非常的烦琐:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf">            <p><font color="#ff0000">以下为引用的内容：</font><br />            startList&nbsp;=&nbsp;function()&nbsp;{ <br />            if&nbsp;(document.all&amp;&amp;document.getElementById)&nbsp;{ <br />            navRoot&nbsp;=&nbsp;document.getElementById(&quot;nav&quot;); <br />            for&nbsp;(i=0;&nbsp;i&lt;navRoot.childNodes.length;&nbsp;i++)&nbsp;{ <br />            node&nbsp;=&nbsp;navRoot.childNodes[i]; <br />            if&nbsp;(node.nodeName==&quot;LI&quot;)&nbsp;{ <br />            node.onmouseover=function()&nbsp;{ <br />            this.className+=&quot;&nbsp;over&quot;; <br />            &nbsp;&nbsp;} <br />            &nbsp;&nbsp;node.onmouseout=function()&nbsp;{ <br />            &nbsp;&nbsp;this.className=this.className.replace&raquo; <br />            &nbsp;(&quot;&nbsp;over&quot;,&nbsp;&quot;&quot;); <br />            &nbsp;&nbsp;&nbsp;} <br />            &nbsp;&nbsp;&nbsp;} <br />            &nbsp;&nbsp;} <br />            &nbsp;} <br />            } <br />            window.onload=startList;</p>            <p>&nbsp;</p>            </td>        </tr>    </tbody></table></p><p>好了,其他代码再做下补充,这个功能就能实现了:</p><p><table style="border-right: #cccccc 1px dotted; table-layout: fixed; border-top: #cccccc 1px dotted; border-left: #cccccc 1px dotted; border-bottom: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">    <tbody>        <tr>            <td style="word-wrap: break-word" bgcolor="#fdfddf"><font color="#ff0000">以下为引用的内容：</font><br />            li:hover&nbsp;ul,&nbsp;li.over&nbsp;ul&nbsp;{&nbsp; <br />            &nbsp;display:&nbsp;block;&nbsp;} <br />            <br />            &lt;ul&nbsp;id=&quot;nav&quot;&gt;</td>        </tr>    </tbody></table></p><p><font face="Verdana">自己动手做一个吧,可以更好看些</font></p>]]></description><category>DIV+CSS</category><comments>http://www.itlanmei.com/blog/cat_6/div123.html#comment</comments><wfw:comment>http://www.itlanmei.com/blog/</wfw:comment><wfw:commentRss>http://www.itlanmei.com/blog/feed.asp?cmt=15</wfw:commentRss><trackback:ping>http://www.itlanmei.com/blog/cmd.asp?act=tb&amp;id=15&amp;key=bc13283c</trackback:ping></item><item><title>网页制作之css技巧十则</title><author>a@b.com (itlanmei)</author><link>http://www.itlanmei.com/blog/cat_6/web1243.html</link><pubDate>Mon, 03 Nov 2008 00:18:26 +0800</pubDate><guid>http://www.itlanmei.com/blog/cat_6/web1243.html</guid><description><![CDATA[<p>　这十则<strong>CSS技巧</strong>汇编于网络，作为老手已经司空见惯了，也没有什么新意，但温故而知新，或许阅读一遍也有一定的启发，本文主要面对CSS新手朋友，有一些东西或许不是搞的很明白。而这十则<strong>CSS技巧</strong>能促进你的学习与编码技巧。</p><p><strong>一、CSS字体属性简写规则</strong></p><p>　　一般用<strong>CSS</strong>设定字体属性方法：<br />　　font-weight:bold;<br />　　font-style:italic;<br />　　font-varient:small-caps;<br />　　font-size:1em;<br />　　line-height:1.5em;<br />　　font-family:verdana,sans-serif;<br />　　可以把它们全部写到一行上去：<br />　　font: bold italic small-caps 1em/1.5em verdana,sans-serif;<br />　　这样看起来是不是简单多了，只有一点要提醒的：这种简写方法只有在同时指定font-size和font-family属性时才起作用。而且，如果你没有设定font-weight, font-style, 以及font-varient，他们会使用缺省值，这点要记上。</p><p><strong>二、CSS border的缺省值</strong></p><p>　　通常可以设定边界的颜色，宽度和风格，如：<br />　　border: 3px solid #000;<br />　　这位把边界显示成3像素宽，黑色，实线。但实际上这里只需要指定风格即可。<br />　　如果只指定了风格，其他属性就会使用缺省值。一般地，Border的宽度缺省是medium，一般等于3到4个像素；缺省的颜色是其中文字的颜色。如果这个值正好合适的话，就不用设那么多了。</p><p><strong>三、给元素同时使用两个类</strong></p><p>　　一般一个元素设定一个类（Class），但这并不意味着不能用两个。事实上，你可以这样：<br />　　&lt;p class=&rdquo;text side&rdquo;&gt;&hellip;&lt;/p&gt;<br />　　同时给P元素两个类，中间用空格格开，这样所有text和side两个类的属性都会加到P元素上来。如果它们两个类中的属性有冲突的话，后设置的起作用，即在CSS文件中放在后面的类的属性起作用。<br />　　补充：对于一个ID，不能这样写&lt;p id=&rdquo;text side&rdquo;&gt;&hellip;&lt;/p&gt;也不能这样写</p><p><strong>四、CSS用于文档打印</strong></p><p>　　许多网站上都有一个针对打印的版本，但实际上这并不需要，因为可以用CSS来设定打印风格。<br />也就是说，可以为页面指定两个CSS文件，一个用于屏幕显示，一个用于打印：<br />　　&lt;link type=&rdquo;text/css&rdquo; rel=&rdquo;stylesheet&rdquo; href=&rdquo;stylesheet.css&rdquo; media=&rdquo;screen&rdquo; /&gt;<br />　　&lt;link type=&rdquo;text/css&rdquo; rel=&rdquo;stylesheet&rdquo; href=&rdquo;printstyle.css&rdquo; media=&rdquo;print&rdquo; /&gt;<br />　　第1行就是显示，第2行是打印，注意其中的media属性。<br />　　但应该在打印CSS中写什么东西呢？你可以按设计普通CSS的方法来设定它。设计的同时就可以把这个CSS设成显示CSS来检查它的效果。也许你会使用display: none 这个命令来关掉一些装饰图片，再关掉一些导航按钮等。</p><p><strong>五、CSS图片替换技巧</strong></p><p>　　一般都建议用标准的HTML来显示文字，而不要使用图片，这样不但快，也更具可读性。但如果你想用一些特殊字体时，就只能用图片了。<br />　　比如你想整个卖东西的图标，你就用了这个图片：<br />　　&lt;h1&gt;&lt;img src=&rdquo;widget-image.gif&rdquo; alt=&rdquo;Buy widgets&rdquo; /&gt;&lt;/h1&gt;<br />　　这当然可以，但对搜索引擎来说，和正常文字相比，它们对alt里面的替换文字几乎没有兴趣这是因为许多设计者在这里放许多关键词来骗<a href="http://www.kingar.com/blog/catalog.asp?tags=搜索引擎"><font color="#557700">搜索引擎</font></a>。所以方法应该是这样的：<br />　　&lt;h1&gt;Buy widgets&lt;/h1&gt;<br />　　但这样就没有特殊字体了。要想达到同样效果，可以这样设计CSS：<br />　　h1 { background: url(widget-image.gif) no-repeat; height: image height text-indent: -2000px }<br />　　注意把image height换成真的图片的高度。这里，图片会当作背景显示出来，而真正的文字由于设定了-2000像素这个缩进，它们会出现在屏幕左边2000点的地方，就看不见了。但这对于关闭图片的人来说，可能全部看不到了，这点要注意。</p><p><strong>六、CSS box模型的另一种技巧</strong></p><p>　　这个Box模型的调整主要是针对IE6之前的IE浏览器的，它们把边界宽度和空白都算在元素宽度上。比如：<br />　　#box { width: 100px; border: 5px; padding: 20px }<br />　　这样调用它：<br />　　&lt;div id=&rdquo;box&rdquo;&gt;&hellip;&lt;/div&gt;<br />　　这时盒子的全宽应该是150点，这在除IE6之前的IE浏览器之外的所有浏览器上都是正确的。但在IE5这样的浏览器上，它的全宽仍是100点。可以用以前人发明的Box调整方法来处理这种差异。<br />　　但用CSS也可以达到同样的目的，让它们显示效果一致。<br />　　#box { width: 150px }<br />　　#box div { border: 5px; padding: 20px }<br />　　这样调用：<br />　　&lt;div id=&rdquo;box&rdquo;&gt;&lt;div&gt;&hellip;&lt;/div&gt;&lt;/div&gt;<br />　　这样，不管什么浏览器，宽度都是150点了。</p><p><strong>七、CSS设置块元素水平居中对齐</strong></p><p>　　如果想做个固定宽度的网页并且想让网页水平居中的话，通常是这样：<br />　　#content { width: 700px; margin: 0 auto }<br />　　你会使用 &lt;div id=&rdquo;content&rdquo;&gt; 来围上所有元素。这很简单，但不够好，IE6之前版本会显示不出这种效果。改CSS如下：<br />　　body { text-align: center } #content { text-align: left; width: 700px; margin: 0 auto }<br />　　这会把网页内容都居中，所以在Content中又加入了:text-align: left 。<br />　　</p><p><strong>八、用CSS来处理垂直对齐</strong></p><p>　　垂直对齐用表格可以很方便地实现，设定表格单元 vertical-align: middle 就可以了。但对CSS来说这没用。如果你想设定一个导航条是2em高，而想让导航文字垂直居中的话，设定这个属性是没用的。<br />　　CSS方法是什么呢？对了，把这些文字的行高设为 2em：line-height: 2em ，这就可以了。</p><p><strong>九、CSS在容器内的定位</strong></p><p>　　CSS的一个好处是可以把一个元素任意定位，在一个容器内也可以。比如对这个容器：<br />　　#container { position: relative }<br />　　这样容器内所有的元素都会相对定位，可以这样用：<br />　　&lt;div id=&rdquo;container&rdquo;&gt;&lt;div id=&rdquo;navigation&rdquo;&gt;&hellip;&lt;/div&gt;&lt;/div&gt;<br />　　如果想定位到距左30点，距上5点，可以这样：<br />　　#navigation { position: absolute; left: 30px; top: 5px }<br />　　当然，你还可以这样：<br />　　margin: 5px 0 0 30px<br />　　注意4个数字的顺序是：上、右、下、左。当然，有时候定位的方法而不是边距的方法更好些。<br />　　更多的CSS布局与技术，请参考52CSS.com的大量教程。</p><p><strong>十、直通到屏幕底部的背景色</strong></p><p>　　在垂直方向是进行控制是CSS所不能的。如果你想让导航栏和内容栏一样直通到页面底部，用表格是很方便的，但如果只用这样的CSS：<br />　　#navigation { background: blue; width: 150px }<br />　　较短的导航条是不会直通到底部的，半路内容结束时它就结束了。该怎么办呢？<br />　　不幸的是，只能采用欺骗的手段了，给这较短的一栏加上个背景图，宽度和栏宽一样，并让它的颜色和设定的背景色一样。<br />　　body { background: url(blue-image.gif) 0 0 repeat-y }<br />　　此时不能用em做单位，因为那样的话，一旦读者改变了字体大小，这个花招就会露馅，只能使用px。</p>]]></description><category>DIV+CSS</category><comments>http://www.itlanmei.com/blog/cat_6/web1243.html#comment</comments><wfw:comment>http://www.itlanmei.com/blog/</wfw:comment><wfw:commentRss>http://www.itlanmei.com/blog/feed.asp?cmt=5</wfw:commentRss><trackback:ping>http://www.itlanmei.com/blog/cmd.asp?act=tb&amp;id=5&amp;key=32a986f7</trackback:ping></item></channel></rss>
