告诉你一个非常好用的css样式,特别好用
box-sizing: border-box
即使加了padding或者margin属性都会有奇效哦
另外,你上面的滚动条改为overflow: auto
至于高度百分比问题,需要设置一下:
html,body{height:100%}
而且,你所设置80%高度的标签父级标签也要设一下,我随便写了一个案例,你看看,本来加了padding后实际显示的高度会大于设置的高度,但是加了box-sizing: border-box后,显示的高度还是50%
<style type="text/css">html,body{ height:100% margin:0 padding:0}
</style>
</head>
<body>
<div style=" height:100% background:red">
<div style=" height:600px background:blue">
<div style=" height:50% background:green padding:50px overflow:auto box-sizing: border-box">
<div style="height:1000px background:black color:white">这是内容部分</div>
</div>
</div>
</div>
</body>
纯css实现的大图浏览<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS examples - A:hover图片预览效果--By:小web</title>
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8" />
<mce:style type="text/css"><!--
*{
position:relative
}
img {
border:none
}
#room{
width:520px
margin:50px auto
text-align:centerfont-size:13px
}
#room a{
display:block
width:100pxheight:100px
margin:5pxpadding:5px
float:left
line-height:25px
border:1px solid graybackground:#ccc
}
#room a img{
width:100pxheight:100px
}
#room a:hover{/*IE6的bug在这个设置中可以消除*/
background:none
color:#0065FF
z-index:1000
}
#room a:hover img{
display:block
width:200pxheight:200px
margin-left:-100pxpadding:2px
position:absoluteleft:50%top:-50px
border:1px solid graybackground:#fff
}
--></mce:style><style type="text/css" mce_bogus="1">
*{
position:relative
}
img {
border:none
}
#room{
width:520px
margin:50px auto
text-align:centerfont-size:13px
}
#room a{
display:block
width:100px
height:100px
margin:5px
padding:5px
float:left
line-height:25px
border:1px solid graybackground:#ccc
}
#room a img{
width:100pxheight:100px
}
#room a:hover{/*IE6的bug在这个设置中可以消除*/
background:none
color:#0065FF
z-index:1000
}
#room a:hover img{
display:block
width:200pxheight:200px
padding:2px
position:absoluteleft:-25%top:-25%
border:1px solid graybackground:#fff
}</style>
</head>
<body>
<div id="room">
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_1.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_1.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_2.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_2.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_3.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_3.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_4.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_4.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_5.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_5.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_6.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_6.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_7.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_7.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_8.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_8.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_9.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_9.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_10.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_10.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_11.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_11.jpg" alt="星坐" /></a>
<a href="#" mce_href="#"><img src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_12.jpg" mce_src="http://images.cnblogs.com/cnblogs_com/littleweb/170141/r_12.jpg" alt="星坐" /></a>
</div>
</body>
</html>