由于显示器的大小不一样,设置的分辨率也不一样,有时候在这台电脑上看到的网页都能显示正确的位置,在另外的电脑上却不能,这多数是因为分辩率问题,也有的时候要拖动下边的滚动条才能显示完全。这样在浏览的时候非常不方便,因此很想让网页根据不同的分辩率自动变化,下面就有几种方法:
1、做不同分辩率的网页,在用js判断分别转到相应的页面。
<script>if (window.screen.width==1440){ document.href=’a.html’ }
elseif(window.screen.width==1024)
{document.href=’b.html’}
else{ document.href=’c.html’}</script>
2、如果是表格设计的网页,可以用百分比来设置网页 width=85%,width=100% 这样,所有与高度和宽度都用百分比,网页就会根据不同的分辨率自动调整。
3、如果是css+div 布局的,可以用下面的方法:
<style type=”text/css”>
<!–
body { margin:0; padding:0; } //这句不是必需,但是能解决某些浏览器上边距留白的问题
#center {
width:1024px; //视网页宽度而定
margin:0 auto; //意思是网页上下边距为0,左右边距自适应
}
font {
font-size: 12px;
line-height: 20px;
color: #3e6074;
text-align: center;
margin-right: auto;
margin-left: auto;
}
font a {
color: #3E6074;
text-decoration: none;
}
a:hover {
color: #0099CC;
}
–>
</style>
</head>
<body>
<div id=”center”>网页内容</dive></body>