1、如何清除图片下方出现几像素的空白间隙?
img{display:block;}
img{vertical-align:top;}
#test{font-size:0;line-height:0;}
2、如何让文本垂直对齐文本输入框?
input{vertical-align:middle;}
3、如何让单行文本在容器内垂直居中?
#test{height:25px;line-height:25px;}
4、如何让超链接访问后和访问前的颜色不同且访问后仍保留hover和active效果?
a:link{color:#03c;} a:visited{color:#666;} a:hover{color:#f30;} a:active{color:#c30;}
5、为什么Standard mode下IE无法设置滚动条的颜色?
html{ scrollbar-3dlight-color:#999; scrollbar-darkshadow-color:#999; scrollbar-highlight-color:#fff; scrollbar-shadow-color:#eee; scrollbar-arrow-color:#000; scrollbar-face-color:#ddd; scrollbar-track-color:#eee; scrollbar-base-color:#ddd; }
6、如何使文本溢出边界不换行强制在一行内显示?
#test{width:150px;white-space:nowrap;}
7、如何使文本溢出边界显示为省略号?
#test{width:150px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
8、如何使连续的长字符串自动换行?
#test{width:150px;word-wrap:break-word;}
9、如何清除浮动?
#test{clear:both;}
#test{display:block;zoom:1;overflow:hidden;}
#test{zoom:1;}
#test:after{display:block;clear:both;visibility:hidden;height:0;content:'';}
10、如何定义鼠标指针的光标形状为手型并兼容所有浏览器?
#test{cursor:pointer;}
11、如何让已知高度的容器在页面中水平垂直居中?
#test{position:absolute;top:50%;left:50%;width:200px;height:200px;margin:-100px 0 0 -1
12、如何让未知尺寸的图片在已知宽高的容器内水平垂直居中?
#test{display:table-cell;*display:block;*position:relative;width:200px;height:200px;text-align:center;vertical-align:middle;}
#test p{*position:absolute;*top:50%;*left:50%;margin:0;}
#test p img{*position:relative;*top:-50%;*left:-50%;vertical-align:middle;}
13、如何设置span的宽度和高度(即如何设置内联元素的宽高)?
span{display:block;width:200px;height:100px;}
14、如何给一个元素定义多个不同的css规则?
.a{color:#f00;} .b{background:#eee;} .c{background:#ccc;} <div class="a b">测试1</div> <div class="a c">测试2</div>
15、如何让某个元素充满整个页面?
html,body{height:100%;margin:0;}
#test{height:100%;}
16、如何让某个元素距离窗口上右下左4边各10像素?
html,body{height:100%;margin:0;} html{_padding:10px;} #test{position:absolute;top:10px;right:10px;bottom:10px;left:10px;_position:static;_height:100%;}
17、如何去掉超链接的虚线框?
a{outline:none;}
18、如何容器透明,内容不透明?
.outer{width:200px;height:200px;background:#000;filter:alpha(opacity=20);opacity:.2;} .inner{width:200px;height:200px;margin-top:-200px;} <div class="outer"><!--我是透明的容器--></div> <div class="inner">我是不透明的内容</div>
.outer{width:200px;height:200px;background:rgba(0,0,0,.2);background:#000;filter:alpha(opacity=20);} .outer .inner{position:relative;} <div class="outer"> <div class="inner">我是不透明的内容</div> </div>
19、如何让整个页面水平居中?
body{text-align:center;}
#test2{width:960px;margin:0 auto;text-align:left;}
20、为什么容器的背景色没显示出来?为什么容器无法自适应内容高度?
21、如何做1像素细边框的table?
#test{border-collapse:collapse;border:1px solid #ddd;} #test th,#test td{border:1px solid #ddd;} <table id="test"> <tr><th>姓名</th><td>Joy Du</td></tr> <tr><th>年龄</th><td>26</td></tr> </table>
#test{border-spacing:1px;background:#ddd;} #test tr{background:#fff;} <table id="test" cellspacing="1"> <tr><th>姓名</th><td>Joy Du</td></tr> <tr><th>年龄</th><td>26</td></tr> </table>
如何使页面文本行距始终保持为n倍字体大小的基调?
body{line-height:n;}
22、标准模式Standard mode和怪异模式Quirks mode下的盒模型区别?
怪异模式下:Element width = width
23、以图换字的几种方法及优劣分析
.test1{width:200px;height:50px;text-indent:-9999px;background:#eee url(*.png) no-repeat;} <div class="test">以图换字之内容负缩进法</div>
.test{width:200px;height:50px;background:#eee url(*.png) no-repeat;} .test span{visibility:hidden;/* 或者display:none */} <div class="test"><span>以图换字之内容隐藏法</span></div>
.test{overflow:hidden;width:200px;height:0;padding-top:50px;background:#eee url(*.png) no-repeat;} .test{overflow:hidden;width:200px;height:50px;line-height:50;background:#eee url(*.jpg) no-repeat;} <div class="test">以图换字之内容排挤法</div>
.test{overflow:hidden;width:200px;height:50px;font-size:0;line-height:0;color:rgba(0,0,0,0);background:#eee url(*.png) no-repeat;} <div class="test">以图换字之超小字体+文本全透明法</div>
24、为什么2个相邻div的margin只有1个生效?
.box1{margin:10px 0;} .box2{margin:20px 0;} <div class="box1">box1</div> <div class="box2">box2</div>
外边距合并只出现在块级元素上;
浮动元素不会和相邻的元素产生外边距合并;
绝对定位元素不会和相邻的元素产生外边距合并;
内联块级元素间不会产生外边距合并;
根元素间不会不会产生外边距合并(如html与body间);
设置了属性overflow且值不为visible的块级元素不会与它的子元素发生外边距合并;
25、如何在文本框中禁用中文输入法?
input,textarea{ime-mode:disabled;}