<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>生活点滴 &#187; css</title>
	<atom:link href="http://www.storyday.com/tag/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.storyday.com</link>
	<description>生活点滴、旅游、web技术、虚拟主机、电子信息</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:54:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>一些CSS小窍门</title>
		<link>http://www.storyday.com/html/y2008/1778_some-css-tips.html</link>
		<comments>http://www.storyday.com/html/y2008/1778_some-css-tips.html#comments</comments>
		<pubDate>Sun, 24 Aug 2008 11:42:02 +0000</pubDate>
		<dc:creator>江东</dc:creator>
				<category><![CDATA[网站技术]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.storyday.com/?p=1778</guid>
		<description><![CDATA[CSS兼容是一个很头疼的问题，浏览器太多，有不守规矩的IE6、比较守规矩的IE7和将来不知道怎么去守规矩的IE8，不断进化的IE和多浏览器共存将会给很多web开发者带来新一轮的头疼问题。朋友可能注意到，我前面的浏览器都只提了IE，而没有说FireFox。可能在以前，很多web开发者特别是国内的web开发者根本就没有兼容的这个烦恼，首先他们不关心Firefox，并且那个时候的页面也不是DIV+CSS模式，即使后来DIV+CSS模式流行起来了，他们依然不关心兼容的问题，因为在他们心中就只有一个IE6，需要和谁兼容去？可是如今IE也开始不让他们消停了，这不得不说是一件好事情。首先IE本身的多版本已经让国内大多数开发者开始注意兼容的问题了，而从IE7可以看得出来，微软也慢慢的在向标准靠近，最终解放的还是we开发者。而微软浏览器特有的渲染效果逐渐被淡化也是一个很好的现象，至少我们现在很少看到网页在用vbs脚本了！ cosbeta在业余做网页的过程中也遇到不少的麻烦，然而都能很好的解决掉了，在此过程中，也算是积累了不少的经验，打算在这里写下来，和大家一起分享。 div居中的问题。有这样一个需求，整个网页的宽度是800px，需要将页面居中，如本blog（storyday.com）。可能你会这样解决(为了方便，下面的css代码多直接写在div中，实际使用请自行选择css代码的嵌入方式) main left right footer 用IE打开看，相当完美，可是你用FF打开看看，问题出来了，因为没有float属性的id=page的div并不会自动适应高度，所以#page没有像你希望的那样将left和right都包含进来了，IE7也是如此，那么下面是我常用的解决办法，今后遇到类似的情况可以如此解决，请注意看class=”page”的css代码: main left right footer UL的问题这个困扰了很多朋友的问题，cosbeta也常常在论坛上遇到这样的提问，因为如论怎么修改，列表在IE和FF中就是不一样，所以这个时候我们要将ul的padding和margin属性给指定出来，如ul{margin:0;padding:0;list-style:none} ul li{margin:0;padding:0},之后你就会发现他们的效果是一样的了，归根结底还是浏览器对ul的默认显示效果不一样所导致。 空DIV问题和clear:both的问题 空div的问题如下 这段代码在FF下很正常，div的高度确实是1px，可是在IE下，该DIV怎么都高于1px，于是这个高度差，往往导致整个页面的不协调，这个原因是IE默认div的高度为当前字体的高度，所以比字体小的高度是无法显示正常的，那么知道这一点之后，我们可以这样修改 clear:both这个css属性是我们在用float方式排版中最重要的工具，比如3个div，left，right和footer，我们需要footer在left和right的下方，即footer换行排列，如果不采用clear:both，可能会不能满足你的要求，不相信看下面的两个例子 left right footer 加了clear:both之后： left right footer 所以在实际做网页的时候，我们可以定义一个div，样式表为.clear{clear:both;height:1px;font-size:1px}在需要换行的地方，直接插入一个div class=”clear”即可，这个算是cosbeta的技巧，不知道你如何认为呢？ !important的使用我们都知道，在css中总是以最后定义的为准，比如egg{width:100px;height:100px;width:200px},那么实际生效的width应该是200px，而FF和IE有一个important属性，IE6不支持该属性，所以一个DIV，由于不兼容导致我们需要在IE7、FF中设置高度为100px，在IE6中设置为90px，那么CSS可以这样写 .mydiv{width:100px !important;width:90px}可能这个特性基本都用过吧 其实css 兼容技巧都是在实际中总结出来的，由于记忆的问题，就没有办法一一列举出来，比如上次和zhiqiang讨论一个css的时候就遇到一个怪异的问题，两个div，如果没有border，则总会分开，当设置border为1的时候他们就结合在一起了，至今不知道原因何在。所以如果有朋友如有更多的实战经验，欢迎留言，大家一起记录下来。]]></description>
			<content:encoded><![CDATA[<p>CSS兼容是一个很头疼的问题，浏览器太多，有不守规矩的IE6、比较守规矩的IE7和将来不知道怎么去守规矩的IE8，不断进化的IE和多浏览器共存将会给很多web开发者带来新一轮的头疼问题。朋友可能注意到，我前面的浏览器都只提了IE，而没有说FireFox。可能在以前，很多web开发者特别是国内的web开发者根本就没有兼容的这个烦恼，首先他们不关心Firefox，并且那个时候的页面也不是DIV+CSS模式，即使后来DIV+CSS模式流行起来了，他们依然不关心兼容的问题，因为在他们心中就只有一个IE6，需要和谁兼容去？可是如今IE也开始不让他们消停了，这不得不说是一件好事情。首先IE本身的多版本已经让国内大多数开发者开始注意兼容的问题了，而从IE7可以看得出来，微软也慢慢的在向标准靠近，最终解放的还是we开发者。而微软浏览器特有的渲染效果逐渐被淡化也是一个很好的现象，至少我们现在很少看到网页在用vbs脚本了！</p>
<p><a href="http://storyday.com">cosbeta</a>在业余做网页的过程中也遇到不少的麻烦，然而都能很好的解决掉了，在此过程中，也算是积累了不少的经验，打算在这里写下来，和大家一起分享。</p>
<ol>
<li><strong>div居中的问题</strong>。有这样一个需求，整个网页的宽度是800px，需要将页面居中，如本blog（storyday.com）。可能你会这样解决(为了方便，下面的css代码多直接写在div中，实际使用请自行选择css代码的嵌入方式)<br />
<code></p>
<style>
body {margin:5px 0;padding:0;
	font-size:12px;TEXT-ALIGN: center;
	font-family: arial, helvetica, sans-serif;TEXT-ALIGN: center;background:#FFF;	
}
HTML BODY {	TEXT-ALIGN: center;}
div{MARGIN: 0px auto; font-family: arial, helvetica, sans-serif;text-align:left;
} 
</style>
<div style="width:800px;border:1px solid red;padding:2px;" id="page">
  main</p>
<div style="width:280px;float:left;height:300px;border:1px solid green">left</div>
<div style="width:500px;float:left;height:200px;border:1px solid green">right</div>
</p></div>
<div style="border:1px solid red;width:100%;float:left">footer</div>
<p></code><br />
用IE打开看，相当完美，可是你用FF打开看看，问题出来了，因为没有float属性的id=page的div并不会自动适应高度，所以#page没有像你希望的那样将left和right都包含进来了，IE7也是如此，那么下面是我常用的解决办法，今后遇到类似的情况可以如此解决，请注意看class=”page”的css代码:<span id="more-1778"></span><br />
<code><br />
<style>
body {margin:5px 0;padding:0;
	font-size:12px;TEXT-ALIGN: center;
	font-family: arial, helvetica, sans-serif;TEXT-ALIGN: center;background:#FFF;	
}
HTML BODY {	TEXT-ALIGN: center;}
div{MARGIN: 0px auto; font-family: arial, helvetica, sans-serif;text-align:left;
}
.page{width:100%;float:left;border:1px solid #000}/*解决的方法是在id=page中嵌入一个width=100%，具有float属性的div*/
</style>
<p> <body style="align:center"></p>
<div style="width:800px;border:1px solid red;padding:2px;" id="page">
<div class="page">
  main</p>
<div style="width:280px;float:left;height:300px;border:1px solid green">left</div>
<div style="width:500px;float:left;height:200px;border:1px solid green">right</div>
</p></div>
</p></div>
<div style="border:1px solid red;width:100%;float:left">footer</div>
<p> </body></code>
</li>
<li><strong>UL的问题</strong>这个困扰了很多朋友的问题，<a href="http://storyday.com">cosbeta</a>也常常在论坛上遇到这样的提问，因为如论怎么修改，列表在IE和FF中就是不一样，所以这个时候我们要将ul的padding和margin属性给指定出来，如<code>ul{margin:0;padding:0;list-style:none} ul li{margin:0;padding:0}</code>,之后你就会发现他们的效果是一样的了，归根结底还是浏览器对ul的默认显示效果不一样所导致。
</li>
<li><strong>空DIV问题和clear:both的问题</strong> 空div的问题如下<br />
 <code>
<div style="border:1px solid red;height:1px;width:100px;"></div>
<p></code>这段代码在FF下很正常，div的高度确实是1px，可是在IE下，该DIV怎么都高于1px，于是这个高度差，往往导致整个页面的不协调，这个原因是IE默认div的高度为当前字体的高度，所以比字体小的高度是无法显示正常的，那么知道这一点之后，我们可以这样修改<code>
<div style="border:1px solid red;height:1px;width:100px;font-size:1px"></div>
<p></code></p>
<p>clear:both这个css属性是我们在用float方式排版中最重要的工具，比如3个div，left，right和footer，我们需要footer在left和right的下方，即footer换行排列，如果不采用clear:both，可能会不能满足你的要求，不相信看下面的两个例子<br />
<code>
<div style="width:280px;float:left;height:300px;border:1px solid green">left</div>
<div style="width:500px;float:left;height:100px;border:1px solid green">right</div>
<div style="border:1px solid red;width:400px;float:left">footer</div>
<p> </code><br />
加了clear:both之后：<br />
<code>
<div style="width:280px;float:left;height:300px;border:1px solid green">left</div>
<div style="width:500px;float:left;height:100px;border:1px solid green">right</div>
<div style="border:1px solid red;width:400px;float:left;clear:both">footer</div>
<p> </code><br />
所以在实际做网页的时候，我们可以定义一个div，样式表为.clear{clear:both;height:1px;font-size:1px}在需要换行的地方，直接插入一个div class=”clear”即可，这个算是<a href="http://storyday.com">cosbeta</a>的技巧，不知道你如何认为呢？
</li>
<li><strong>!important的使用</strong>我们都知道，在css中总是以最后定义的为准，比如<code>egg{width:100px;height:100px;width:200px}</code>,那么实际生效的width应该是200px，而FF和IE有一个important属性，IE6不支持该属性，所以一个DIV，由于不兼容导致我们需要在IE7、FF中设置高度为100px，在IE6中设置为90px，那么CSS可以这样写<br />
<code>.mydiv{width:100px !important;width:90px}</code>可能这个特性基本都用过吧
</li>
</ol>
<p>其实css 兼容技巧都是在实际中总结出来的，由于记忆的问题，就没有办法一一列举出来，比如上次和<a href="http://zhiqiang.org/blog" target="_blank">zhiqiang</a>讨论一个css的时候就遇到一个怪异的问题，两个div，如果没有border，则总会分开，当设置border为1的时候他们就结合在一起了，至今不知道原因何在。所以如果有朋友如有更多的实战经验，欢迎留言，大家一起记录下来。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.storyday.com/html/y2008/1778_some-css-tips.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>google的圆角代码</title>
		<link>http://www.storyday.com/html/y2008/1524_google-round-corners.html</link>
		<comments>http://www.storyday.com/html/y2008/1524_google-round-corners.html#comments</comments>
		<pubDate>Mon, 28 Apr 2008 06:45:43 +0000</pubDate>
		<dc:creator>江东</dc:creator>
				<category><![CDATA[HTML客户端]]></category>
		<category><![CDATA[网站技术]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.storyday.com/?p=1524</guid>
		<description><![CDATA[不整点圆角怎么能算是2.0呢，所以我在bloggermap的新版设计中全部采用了圆角。下图是正在孕育中的新版bloggermap界面截图 而那个圆角是采用google的圆形背景来作为转角实现的，具体的思路如下图所示： 将一个DIV分作上中下三部分，上和下部分又由ABC三部分组成，A是一个有1/4圆角背景的DIV，同样C也是，当然啦，背景采用的是同一幅图，通过background-position来实现背景的偏移，下面是代码，包括CSS和HTML部分。 这里是效果，呵呵 这里是效果，呵呵 确切的说，上面的代码和google关系不大，仅仅是圆形背景采用了google的图片而已。注意由于IE6对png图片的支持有限，所以该效果在IE6下有点别扭，IE7和FF正常。管他的呢，IE6马上就要推出历史的舞台了。好了，下面正式分享另外一个纯google的圆角中空样式（可惜我今天才发现，要不然就得节约我很多资源了） 代码： Tell us how we're doing: Please answer a few questions about your experience to help us improve our Help Center. 效果： Tell us how we&#8217;re doing: Please answer a few questions about your experience to help us improve our Help Center. &#8212;&#8212;&#8212;&#8212;&#8211;华丽的结束此文&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;]]></description>
			<content:encoded><![CDATA[<p>不整点圆角怎么能算是2.0呢，所以我在<a href="http://bloggermap.org/">bloggermap</a>的新版设计中全部采用了圆角。下图是正在孕育中的新版<a href="http://bloggermap.org/">bloggermap</a>界面截图<img src="http://0bad.com/readimg.php?src=http%3A%2F%2Flh6.gouride.com%2Fchina.cos%2FSBVwDdkzXqI%2FAAAAAAAABP0%2FRSBLXe-cZmo%2Fs400%2Fbloggermap.jpg" alt="" /><br />
而那个圆角是采用google的圆形背景来作为转角实现的，具体的思路如下图所示：<span id="more-1524"></span><br />
<img src="http://0bad.com/readimg.php?src=http%3A%2F%2Flh6.gouride.com%2Fchina.cos%2FSBVwEdkzXrI%2FAAAAAAAABP8%2F8Kw6S_fyRCM%2Fs400%2Fround.jpg" alt="" /><br />
将一个DIV分作上中下三部分，上和下部分又由ABC三部分组成，A是一个有1/4圆角背景的DIV，同样C也是，当然啦，背景采用的是同一幅图，通过background-position来实现背景的偏移，下面是代码，包括CSS和HTML部分。<br />
<code></p>
<style>
/*
round
*/
.t{width:100%;clear:both;height:6px;background:#fc3;font-size:2px;}
.i{width:100%;}
.l,.r{width:6px;height:6px;font-size:2px;
background:#fff url(http://google.com/groups/roundedcorners?a=af&#038;c=ffcc33&#038;w=6&#038;h=6) no-repeat 0 0;float:left;
/*http://google.com/groups/roundedcorners?a=af&#038;c=ffcc33&#038;w=6&#038;h=6使用这个地址居然无法显示*/
}
.r{float:right; background-position:-6px 0 ;margin: 0}
.b{ background-position: 0 -6px;}
.rb{ background-position: -6px -6px;margin: 0}
.rc1{BACKGROUND: #fc3;color:#000;margin:0;width:100%;overflow:visible;float:left;}
.blocklogin{margin-top:40px;width:450px;}
.block{width:99%;margin-top:10px;}
/* round end */
</style>
<div class="block">
<div class="t">
<div class="l"></div>
<div class="r"></div>
</div>
<div class="rc1 i">
<p>这里是效果，呵呵</p>
</p></div>
<div class="t">
<div class="l b"></div>
<div class="r rb"></div>
</div>
</div>
<p></code></p>
<style>
/*
round
*/
.t{width:100%;clear:both;height:6px;background:#fc3;font-size:2px;}
.i{width:100%;}
.l,.r{width:6px;height:6px;font-size:2px;
background:#fff url(http://lh6.ggpht.com/china.cos/SBVz5dkzXsI/AAAAAAAABQI/KDmXEs5Da2Y/s144/roundedcorners.png) no-repeat 0 0;float:left;
/*http://google.com/groups/roundedcorners?a=af&#038;c=ffcc33&#038;w=6&#038;h=6 使用这个地址居然无法显示*/
}
.r{float:right; background-position:-6px 0 ;margin: 0}
.b{ background-position: 0 -6px;}
.rb{ background-position: -6px -6px;margin: 0}
.rc1{BACKGROUND: #fc3;color:#000;margin:0;width:100%;overflow:visible;float:left;}
.blocklogin{margin-top:40px;width:450px;}
.block{width:99%;margin-top:10px;}
/* round end */
</style>
<div class="block">
<div class="t">
<div class="l"></div>
<div class="r"></div>
</div>
<div class="rc1 i">
<p>这里是效果，呵呵</p>
</p></div>
<div class="t">
<div class="l b"></div>
<div class="r rb"></div>
</div>
</div>
<p><b>确切的说，上面的代码和google关系不大，仅仅是圆形背景采用了google的图片而已。注意由于IE6对png图片的支持有限，所以该效果在IE6下有点别扭，IE7和FF正常。管他的呢，IE6马上就要推出历史的舞台了。好了，下面正式分享另外一个纯google的圆角中空样式（可惜我今天才发现，要不然就得节约我很多资源了）</b><br />
代码：<br />
<code></p>
<style>
<p>  table.survey_invite{ margin-top: 20px; margin-bottom: 20px; background: #fefde6; color: #010101; }
  table.survey_invite tr.row1 td.td1{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_topleft.gif) top left no-repeat; }
  table.survey_invite tr.row1 td.td2{ height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) top left repeat-x; }
  table.survey_invite tr.row1 td.td3{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_topright.gif) top right no-repeat; }
  table.survey_invite tr.row2 td.td1{ width: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) top left repeat-y; }
  table.survey_invite tr.row2 td.td2{ padding: 3px; }
  table.survey_invite tr.row2 td.td3{ width: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) top right repeat-y; }
  table.survey_invite tr.row3 td.td1{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_bottomleft.gif) bottom left no-repeat; }
  table.survey_invite tr.row3 td.td2{ height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) bottom left repeat-x; }
  table.survey_invite tr.row3 td.td3{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_bottomright.gif) bottom right no-repeat; }</p>
</style>
<table class="survey_invite" border="0" cellspacing="0" cellpadding="0" align="center">
<tr class="row1">
<td class="td1"></td>
<td class="td2"></td>
<td class="td3"></td>
</tr>
<tr class="row2">
<td class="td1"></td>
<td class="td2">
  <b>Tell us how we're doing:</b> Please answer a few questions about your experience to help us improve our Help Center.
  </td>
<td class="td3"></td>
</tr>
<tr class="row3">
<td class="td1"></td>
<td class="td2"></td>
<td class="td3"></td>
</tr>
</table>
<p></code><br />
效果：</p>
<style>
<p>  table.survey_invite{ margin-top: 20px; margin-bottom: 20px; background: #fefde6; color: #010101; }
  table.survey_invite tr.row1 td.td1{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_topleft.gif) top left no-repeat; }
  table.survey_invite tr.row1 td.td2{ height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) top left repeat-x; }
  table.survey_invite tr.row1 td.td3{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_topright.gif) top right no-repeat; }
  table.survey_invite tr.row2 td.td1{ width: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) top left repeat-y; }
  table.survey_invite tr.row2 td.td2{ padding: 3px; }
  table.survey_invite tr.row2 td.td3{ width: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) top right repeat-y; }
  table.survey_invite tr.row3 td.td1{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_bottomleft.gif) bottom left no-repeat; }
  table.survey_invite tr.row3 td.td2{ height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_stripe.gif ) bottom left repeat-x; }
  table.survey_invite tr.row3 td.td3{ width: 8px; height: 8px; background: url(http://www.google.com/help/hc/images/survey_yellow_bg_bottomright.gif) bottom right no-repeat; }</p>
</style>
<table class="survey_invite" border="0" cellspacing="0" cellpadding="0" align="center">
<tr class="row1">
<td class="td1"></td>
<td class="td2"></td>
<td class="td3"></td>
</tr>
<tr class="row2">
<td class="td1"></td>
<td class="td2">
  <b>Tell us how we&#8217;re doing:</b> Please answer a few questions about your experience to help us improve our Help Center.
  </td>
<td class="td3"></td>
</tr>
<tr class="row3">
<td class="td1"></td>
<td class="td2"></td>
<td class="td3"></td>
</tr>
</table>
<p>&#8212;&#8212;&#8212;&#8212;&#8211;华丽的结束此文&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.storyday.com/html/y2008/1524_google-round-corners.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>CSS兼容性考虑-如何用css固定位置</title>
		<link>http://www.storyday.com/html/y2007/1237_fixedposition.html</link>
		<comments>http://www.storyday.com/html/y2007/1237_fixedposition.html#comments</comments>
		<pubDate>Sun, 14 Oct 2007 03:48:00 +0000</pubDate>
		<dc:creator>江东</dc:creator>
				<category><![CDATA[HTML客户端]]></category>
		<category><![CDATA[网站技术]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.storyday.com/html/y2007/1237_fixedposition.html</guid>
		<description><![CDATA[有的时候我们需要将一个div固定在一个屏幕的指定位置，如在使用loading状态条的时候，或者显示在线用户数的时候。需要的是将div显示在网页的中间，顶端或者左下端，并且无论滚动条如何拉动，这个div将始终保持在相同的相对位置。这些要求用css是很可以容易实现的，只需要用到position:fixed这个描述参数即可。和position: fixed;平行的描述语言有 position: absolute; position: relative; position: static;这里主要讲一讲fixed和absolute的区别，fixed表示始终处于同屏幕的一个位置，即使你拉动滚动条，依然会显示在屏幕的相对位置，而absolute则不一样，absolute针对网页的位置进行描述，所以拉动滚动条后有可能会将显示在中部的div拉动到顶端去，因此，下面的一段css将会把div放在屏幕的中央： #LoadingStatus{ position:fixed ; top:100px;/*始终距离屏幕的高度是100px*/ /*后面的描述和位置无关，所以后面的例子请大家关注本行之前的描述*/ width:220px;height:20px; left:50%; margin:0 0 0 -110px;/* 将div将左端推进一半的长度，这样才能显示到真正的中间 */ border:1px solid red; } 如果你用这段css去做实验的话，我相信多数朋友看不到应有的效果，原因在于你用的是IE，那个对w3标准支持不完善的浏览器，如果你用firefox的话，应该是没有任何问题的。不过我们得承认现实，毕竟IE的浏览器占据了绝大部分市场，所以必须写出兼容IE的css才行。由于IE不支持fixed，因此，可以针对IE和FF写不同的css，如： div#LoadingStatus { position: absolute; left: 0px; top: 0px; } body > div#LoadingStatus { position: fixed;/*这个描述IE不认识，因此针对其他浏览器有效*/ } 上面的代码解决了兼容的问题，但是IE下的依然不能将div固定在屏幕的具体位置，因此我们只有出绝招了，那便是写出兼容的css，代码如下（传说出现表达式的css出现了）： div#LoadingStatus{ left: 50%; top: expression( document.body.scrollTop +100 +'px' );/*按照表达式计算出当前屏幕位置所对应的网页位置*/ } body > [...]]]></description>
			<content:encoded><![CDATA[<p>有的时候我们需要将一个div固定在一个屏幕的指定位置，如在使用loading状态条的时候，或者显示在线用户数的时候。需要的是将div显示在网页的中间，顶端或者左下端，并且无论滚动条如何拉动，这个div将始终保持在相同的相对位置。这些要求用css是很可以容易实现的，只需要用到position:fixed这个描述参数即可。和position: fixed;平行的描述语言有 position: absolute; position: relative; position: static;这里主要讲一讲fixed和absolute的区别，fixed表示始终处于同<strong>屏幕</strong>的一个位置，即使你拉动滚动条，依然会显示在屏幕的相对位置，而absolute则不一样，absolute针对网页的位置进行描述，所以拉动滚动条后有可能会将显示在中部的div拉动到顶端去，因此，下面的一段css将会把div放在<strong>屏幕</strong>的中央：<br />
<code>#LoadingStatus{<br />
position:fixed ;<br />
top:100px;/*始终距离屏幕的高度是100px*/</code></p>
<p>/*后面的描述和位置无关，所以后面的例子请大家关注本行之前的描述*/<br />
width:220px;height:20px;<br />
left:50%;<br />
margin:0 0 0 -110px;/* 将div将左端推进一半的长度，这样才能显示到真正的中间 */<br />
border:1px solid red;<br />
}<!--myurl--><br />
如果你用这段css去做实验的话，我相信<strong>多数</strong>朋友看不到应有的效果，原因在于你用的是IE，那个对w3标准支持不完善的浏览器，如果你用firefox的话，应该是没有任何问题的。不过我们得承认现实，毕竟IE的浏览器占据了绝大部分市场，所以必须写出兼容IE的css才行。由于IE不支持fixed，因此，可以针对IE和FF写不同的css，如：<span id="more-1237"></span><br />
<code>div#LoadingStatus { position: absolute; left: 0px; top: 0px; }<br />
body > div#LoadingStatus { position: fixed;/*这个描述IE不认识，因此针对其他浏览器有效*/ }</code><br />
上面的代码解决了兼容的问题，但是IE下的依然不能将div固定在<strong>屏幕</strong>的具体位置，因此我们只有出绝招了，那便是写出兼容的css，代码如下（传说出现表达式的css出现了）：<!--myurl--><br />
<code><br />
div#LoadingStatus{<br />
  left: 50%;<br />
  top: expression( document.body.scrollTop +100 +'px' );/*按照表达式计算出当前屏幕位置所对应的网页位置*/<br />
}<br />
body > div#LoadingStatus{ position: fixed; left: 0px; top: 100px; }<br />
</code><br />
这样看来似乎已经很完美了，应该能够得到我们需要的效果了，不信，你自己试一试。对不起，让你失望了，这还是不行，因为我们在拉动滚动条的时候，针对IE的那段css中的表达式罢工了，仅仅是载入页面的时候进行了计算，后面就不干活了，这可如何是好？别担心，一个IE的bug而已，我们只要将表达式的值赋给一变量，这个问题就解决了，所以下面的css就可以正常工作了：<br />
<code>#LoadingStatus{<br />
position:fixed !important;/*important针对FF，这样后面的position描述就没有用了 */<br />
position:absolute;/* 针对IE */<br />
top:100px;<br />
top: expression( ( 100 + ( noValue = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );<br />
/*上面这个表达式针对IE，FF不认识该表达式，所以top的值就是100px了 */</p>
<p>margin:0 0 0 -110px;<br />
width:220px;height:19px;<br />
left:50%;<br />
text-align:center;<br />
border:1px solid red;</p>
<p>}</code></p>
<p>那么如何将div固定在左上角或者右下角呢？下面给点css代码，应该自己看看就能明白了：<br />
div#LoadingStatus {<br />
  /* IE5.5+/Win &#8211; this is more specific than the IE 5.0 version */<br />
  right: auto; bottom: auto;<br />
  left: expression( ( -20 &#8211; fixme.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( noValue2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + &#8216;px&#8217; );<br />
  top: expression( ( -10 &#8211; fixme.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( noValue = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + &#8216;px&#8217; );<br />
}<br />
忘记给案例了，要不又有朋友有意见了，案例请参见附件：<a href='http://www.storyday.com/wp-content/uploads/2007/10/fix.html' title='' target="_blank">fix.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.storyday.com/html/y2007/1237_fixedposition.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

