2

原谅我的无知,让我解释一下。

我希望 div 在网页中始终完全可见。它是一个包含随机图片的 div,之后是一个“阅读更多”按钮。因此,如果图像适合 div 并且当页面完全向上滚动时 div 和按钮始终可见,那就太好了。

所以,它的标题,然后是“容器 div”。在“容器 div”中,最上面的第一件事是“阅读更多”的 div。不是position : fixed因为这在手机中效果不佳。我想我必须做类似的事情

width : 50%
height : 
get the current height of the screen - height of the header = this is where it begins
get the current height of the screen - height of the footer - height of a text - height of a button = this is where it stops

但是我该怎么做呢?高度取决于屏幕的尺寸,并基于百分比,因此它也是响应式设计

此外,div 包含一个随机图像,必须自动调整大小以适应而不被拉伸。

随机我的意思是它可能是“肖像形”或“风景形”。我读了这篇文章,但设置只width:100%拉伸“肖像形”图像。

我怎样才能解决这个问题?

提前致谢

对不起我的英语不好。在此处输入图像描述

4

1 回答 1

1

对于固定位置,您可以使用此解决方案,如下所示:What is the simple jQuery way to have a 'position:fixed' (always at top) div?

$(window).scroll(function() {
  $('.headup').css('top', $(this).scrollTop() + "px");
});

对于图像,您可以使用最大宽度:

img {
   max-width: 100%;
}

http://jsfiddle.net/9sTXa/

于 2013-11-10T01:29:15.887 回答