Javascript 浮动Div底部的对齐按钮-引导响应
我试图对齐div底部的一个按钮,当用户向下滚动600px时,该按钮会显示出来 我无法使按钮对齐到我想要的位置,因为当我使用边距顶部时,当屏幕大小改变时,按钮位置也会改变,因为我使用%是因为我希望它能够响应 这是按钮代码和div代码 按钮和divJavascript 浮动Div底部的对齐按钮-引导响应,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我试图对齐div底部的一个按钮,当用户向下滚动600px时,该按钮会显示出来 我无法使按钮对齐到我想要的位置,因为当我使用边距顶部时,当屏幕大小改变时,按钮位置也会改变,因为我使用%是因为我希望它能够响应 这是按钮代码和div代码 按钮和div <div class="topMenu"><button type="button" class="btn btn-sky btn-lg btn-float"><a href="#">Get Started</a
<div class="topMenu"><button type="button" class="btn btn-sky btn-lg btn-float"><a href="#">Get Started</a></button></div>
.topMenu {
display: none;
position: fixed;
top: 0;
width: 100%;
height: 14%;
border-top: 1px solid #000;
background: #337AB7;
z-index: 1;
}
$(document).scroll(function () {
var y = $(this).scrollTop();
if (y > 600) {
$('.topMenu').fadeIn();
} else {
$('.topMenu').fadeOut();
}
});
.topMenu{
显示:无;
位置:固定;
排名:0;
宽度:100%;
身高:14%;
边框顶部:1px实心#000;
背景#337AB7;
z指数:1;
}
$(文档)。滚动(函数(){
var y=$(this.scrollTop();
如果(y>600){
$('.topMenu').fadeIn();
}否则{
$('.topMenu').fadeOut();
}
});
感谢您的帮助。首先,将链接从
按钮中取出。它不是有效的HTML
接下来,您需要使父div的位置相对
和按钮的位置绝对
。给你的按钮一个底部
和左侧
值,你应该很好
.topMenu {
position: relative;
width: 100%;
height: 1000px;
border-top: 1px solid #000;
background: #337AB7;
z-index: 1;
}
button {
position: absolute;
bottom: 0;
left: 50%;
display: none;
}
首先,将链接从按钮
元素中取出。它不是有效的HTML
接下来,您需要使父div的位置相对
和按钮的位置绝对
。给你的按钮一个底部
和左侧
值,你应该很好
.topMenu {
position: relative;
width: 100%;
height: 1000px;
border-top: 1px solid #000;
background: #337AB7;
z-index: 1;
}
button {
position: absolute;
bottom: 0;
left: 50%;
display: none;
}
谢谢,这对我有点作用,但现在按钮显示完全正确。我将对css进行一些修改,看看我能做些什么。:)谢谢,这对我有点作用,但现在按钮显示完全正确。我将对css进行一些修改,看看我能做些什么。:)