我在定位和调整照片大小方面遇到了麻烦。这是图片:
1 block - 这是一张照片,应该始终可见(没有滚动条!),2 和 3 block 大小取决于窗口大小。我应该怎么做?
最佳答案
刚玩过。
试试这个。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script>
$(document).ready(function() {
$photoheight = $('.photo').css('width');
$('.photo').css('height', $photoheight);
$(window).resize(function(){
$photoheight = $('.photo').css('width');
$('.photo').css('height', $photoheight);
});
});
</script>
<style>
.photo {
min-width:200px;
width:25%;
max-width:400px;
background-image:url('http://4.bp.blogspot.com/-KWHpPk4f-kM/TdZY_dxWMRI/AAAAAAAAADc/6FHVzBLY-4o/s1600/flower-1.jpg');
background-position:center center;}
</style>
<body>
<div class="photo"></div>
</body>
</html>
关于html - Css 定位和照片大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9111502/