我有一个小工具栏div,位置:固定,因此当用户滚动时它会移动。工具栏在一个更大的div里面,但我需要工具栏来不滚出父div - 有什么方法可以做到这一点吗?
如果您不明白我的意思,请查看:http://flowmainserver.appspot.com/post (我希望爱心和其他按钮不会滚动出大图像div,因为它们阻碍了评论框)
有没有办法用css实现这个或者我需要javascript吗? 谢谢!
答案 0 :(得分:6)
首先,其他一些指示:
<!DOCTYPE>
声明。 (使用不同的<!DOCTYPE>
声明可能需要您进行一些更改,包括addnig cellspacing="0" cellpadding="0"
到<table>
标记)<center>
元素 - 而是使用margin:auto
和text-align:center;
的组合。<div>
放在内嵌级元素<a>
中,如下所示:<a href="/"><div class="title"></div></a>
。相反,请提供<a>
display:block;
CSS属性。text-indent:-10000px;
将其删除。<link />
- 有时不会<img>
。选择其中一个,然后使用相应的<!DOCTYPE>
alt
标记上<img />
属性,在rows
标记上放置cols
和<textarea>
验证您的HTML文档。这将导致浏览器之间更加一致的行为和更好的可访问性。抛弃一些<h1>
... <h6>
标题,你在搜索引擎优化方面也非常扎实。
关于你的问题......或许如果你只是在背后发表评论?
将其放在.html
文件中:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<base href="http://flowmainserver.appspot.com/" /> <!-- remove this when you put it online -->
<!-- Copyright Cal Smith 2010 $(window).height()-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.scrollTo-min.js" type="text/javascript"></script>
<script type="text/javascript">$(window)._scrollable();</script>
<link href="buttons.css" media="all" rel="stylesheet" type="text/css" />
<link href="main.css" media="all" rel="stylesheet" type="text/css" id="main_css" />
<title>flow | post title</title>
<script type="text/javascript">/*
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
document.location = "http://www.google.com";
}
});
*/</script>
<style type="text/css">
html body {
text-align:center;
}
html body div.pageHolder {
margin:auto;
}
html body a.title {
text-indent:-10000px;
display:block;
}
html body table {
position:relative;
z-index:10;
background:url(imgs/dark_bg.png) repeat;
}
html body table table td {
padding-bottom:5px;
}
</style>
</head>
<body>
<div class="pageHolder" style="margin:auto;">
<a href="/" class="title">Flow</a>
<div class="directory">
<p class="categoryTitle">Post title<span class="categoryTitleBy"> 2 weeks ago by @<a href="#" class="categoryTitleByA">author url</a></span></p>
<div class="postDescription"></div>
<div class="heartOff" title="Click to heart">♥</div>
<div class="commentTab" onclick="$(window).scrollTo( $('#commentBoxTitle'), 380 ); $('#commentBox').focus();" title="Comments">Ξ </div>
<div class="postFull" style="background-image: url(example_full.png); height: 500px; width: 1300px;"></div>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<span class="commentBoxTitle" id="commentBoxTitle">Comment</span>
<textarea id="commentBox" class="commentBox"></textarea>
<div align="right"><div class="commentPostButton">Post</div></div>
</td>
<td>
<div class="commentsHolder">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"><img src="http://s3.amazonaws.com/forrst-production/users/photos/10587/xl.png?1280926926" class="commentUserPic" /></td>
<td><div class="commentBody">Vivamus id mollis quam. Morbi ac commodo nulla. In condimentum orci id nisl volutpat bibendum. Quisque commodo hendrerit lorem quis egestas. Maecenas quis tortor arcu. Vivamus rutrum nunc non neque consectetur quis placerat neque lobortis. Nam vestibulum, arcu sodales feugiat consectetur, nisl orci bibendum elit, eu euismod magna sapien ut nibh. Donec semper quam scelerisque tortor dictum gravida. In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien.</div></td>
</tr>
<tr>
<td valign="top"><img src="http://s3.amazonaws.com/forrst-production/users/photos/7825/xl.png?1278955396" class="commentUserPic" /></td>
<td><div class="commentBody">Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus. Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus.</div></td>
</tr>
<tr>
<td valign="top"><img src="http://s3.amazonaws.com/forrst-production/users/photos/10587/xl.png?1280926926" class="commentUserPic" /></td>
<td><div class="commentBody">Vivamus id mollis quam. Morbi ac commodo nulla. In condimentum orci id nisl volutpat bibendum. Quisque commodo hendrerit lorem quis egestas. Maecenas quis tortor arcu. Vivamus rutrum nunc non neque consectetur quis placerat neque lobortis. Nam vestibulum, arcu sodales feugiat consectetur, nisl orci bibendum elit, eu euismod magna sapien ut nibh. Donec semper quam scelerisque tortor dictum gravida. In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien.</div></td>
</tr>
<tr>
<td valign="top"><img src="http://s3.amazonaws.com/forrst-production/users/photos/7825/xl.png?1278955396" class="commentUserPic" /></td>
<td><div class="commentBody">Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus. Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus.</div></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<div class="footer">created by cal smith</div>
</div>
</div>
</body>
</html>
答案 1 :(得分:1)
请在小工具栏div后面加<div style="clear:both"></div>
。它应该在父div中浮动。
希望有所帮助,
答案 2 :(得分:0)
也许你可以根据自己的需要修改它: